cql3: statement_restrictions: use functional style
Instead of a constructor, use a new function analyze_statement_restrictions() as the entry point. It returns an immutable statement_restrictions object. This opens the door to returning a variant, with each arm of the variant corresponding to a different query plan.
This commit is contained in:
@@ -2164,5 +2164,19 @@ const std::unordered_set<const column_definition*> statement_restrictions::get_n
|
||||
return _not_null_columns;
|
||||
}
|
||||
|
||||
statement_restrictions
|
||||
analyze_statement_restrictions(
|
||||
data_dictionary::database db,
|
||||
schema_ptr schema,
|
||||
statements::statement_type type,
|
||||
const expr::expression& where_clause,
|
||||
prepare_context& ctx,
|
||||
bool selects_only_static_columns,
|
||||
bool for_view,
|
||||
bool allow_filtering,
|
||||
check_indexes do_check_indexes) {
|
||||
return statement_restrictions(db, std::move(schema), type, where_clause, ctx, selects_only_static_columns, for_view, allow_filtering, do_check_indexes);
|
||||
}
|
||||
|
||||
} // namespace restrictions
|
||||
} // namespace cql3
|
||||
|
||||
@@ -132,6 +132,18 @@ public:
|
||||
*/
|
||||
statement_restrictions(schema_ptr schema, bool allow_filtering);
|
||||
|
||||
friend statement_restrictions analyze_statement_restrictions(
|
||||
data_dictionary::database db,
|
||||
schema_ptr schema,
|
||||
statements::statement_type type,
|
||||
const expr::expression& where_clause,
|
||||
prepare_context& ctx,
|
||||
bool selects_only_static_columns,
|
||||
bool for_view,
|
||||
bool allow_filtering,
|
||||
check_indexes do_check_indexes);
|
||||
|
||||
private:
|
||||
statement_restrictions(data_dictionary::database db,
|
||||
schema_ptr schema,
|
||||
statements::statement_type type,
|
||||
@@ -141,6 +153,7 @@ public:
|
||||
bool for_view,
|
||||
bool allow_filtering,
|
||||
check_indexes do_check_indexes);
|
||||
public:
|
||||
|
||||
const std::vector<expr::expression>& index_restrictions() const;
|
||||
|
||||
@@ -397,6 +410,18 @@ public:
|
||||
void validate_primary_key(const query_options& options) const;
|
||||
};
|
||||
|
||||
statement_restrictions analyze_statement_restrictions(
|
||||
data_dictionary::database db,
|
||||
schema_ptr schema,
|
||||
statements::statement_type type,
|
||||
const expr::expression& where_clause,
|
||||
prepare_context& ctx,
|
||||
bool selects_only_static_columns,
|
||||
bool for_view,
|
||||
bool allow_filtering,
|
||||
check_indexes do_check_indexes);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -415,7 +415,7 @@ void modification_statement::build_cas_result_set_metadata() {
|
||||
|
||||
void
|
||||
modification_statement::process_where_clause(data_dictionary::database db, expr::expression where_clause, prepare_context& ctx) {
|
||||
_restrictions = restrictions::statement_restrictions(db, s, type, where_clause, ctx,
|
||||
_restrictions = restrictions::analyze_statement_restrictions(db, s, type, where_clause, ctx,
|
||||
applies_only_to_static_columns(), _selects_a_collection, false /* allow_filtering */, restrictions::check_indexes::no);
|
||||
/*
|
||||
* If there's no clustering columns restriction, we may assume that EXISTS
|
||||
|
||||
@@ -2164,8 +2164,8 @@ select_statement::prepare_restrictions(data_dictionary::database db,
|
||||
restrictions::check_indexes do_check_indexes)
|
||||
{
|
||||
try {
|
||||
return ::make_shared<restrictions::statement_restrictions>(db, schema, statement_type::SELECT, _where_clause, ctx,
|
||||
selection->contains_only_static_columns(), for_view, allow_filtering, do_check_indexes);
|
||||
return ::make_shared<restrictions::statement_restrictions>(restrictions::analyze_statement_restrictions(db, schema, statement_type::SELECT, _where_clause, ctx,
|
||||
selection->contains_only_static_columns(), for_view, allow_filtering, do_check_indexes));
|
||||
} catch (const exceptions::unrecognized_entity_exception& e) {
|
||||
if (contains_alias(e.entity)) {
|
||||
throw exceptions::invalid_request_exception(format("Aliases aren't allowed in the WHERE clause (name: '{}')", e.entity));
|
||||
|
||||
@@ -30,7 +30,7 @@ query::clustering_row_ranges slice(
|
||||
const std::vector<expr::expression>& where_clause, cql_test_env& env,
|
||||
const sstring& table_name = "t", const sstring& keyspace_name = "ks") {
|
||||
prepare_context ctx;
|
||||
return restrictions::statement_restrictions(
|
||||
return restrictions::analyze_statement_restrictions(
|
||||
env.data_dictionary(),
|
||||
env.local_db().find_schema(keyspace_name, table_name),
|
||||
statements::statement_type::SELECT,
|
||||
|
||||
Reference in New Issue
Block a user