drop_index_statement: fix column_family()

All statement objects which derive from cf_statement, including
drop_index_statement, have a column_family() returning the name of the
column family involved in this statement. For most statement this is
known at the time of construction, because it is part of the statement,
but for "DROP INDEX", the user doesn't specify the table's name - just
the index name. So we need to override column_family() to find the
table name.

The existing implementation assert()ed that we can always find such
a table, but this is not true - for example, in a DROP INDEX with
"IF EXISTS", it is perfectly fine for no such table to exist. In this
case we don't want a crash, and not even an except - it's fine that
we just return an empty table name.

Signed-off-by: Nadav Har'El <nyh@scylladb.com>
Message-Id: <20190716180104.15985-1-nyh@scylladb.com>
This commit is contained in:
Nadav Har'El
2019-07-16 21:01:04 +03:00
committed by Avi Kivity
parent 4417e78125
commit 759752947b

View File

@@ -57,11 +57,21 @@ drop_index_statement::drop_index_statement(::shared_ptr<index_name> index_name,
{
}
// A "drop index" statement does not specify the base table's name, just an
// index name. Nevertheless, the virtual column_family() method is supposed
// to return a reasonable table name. If the index doesn't exist, we return
// an empty name (this commonly happens with "if exists").
const sstring& drop_index_statement::column_family() const
{
auto cfm = lookup_indexed_table();
assert(cfm);
return cfm->cf_name();
auto& db = service::get_local_storage_proxy().get_db().local();
if (db.has_keyspace(keyspace())) {
auto schema = db.find_indexed_table(keyspace(), _index_name);
if (schema) {
return schema->cf_name();
}
}
// Return the empty name stored by the superclass
return cf_statement::column_family();
}
future<> drop_index_statement::check_access(const service::client_state& state)