diff --git a/cql3/restrictions/statement_restrictions.cc b/cql3/restrictions/statement_restrictions.cc index ad0ef4d32c..b805d9c6a6 100644 --- a/cql3/restrictions/statement_restrictions.cc +++ b/cql3/restrictions/statement_restrictions.cc @@ -2164,5 +2164,19 @@ const std::unordered_set 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 diff --git a/cql3/restrictions/statement_restrictions.hh b/cql3/restrictions/statement_restrictions.hh index 9f11e5d95b..67a63495ff 100644 --- a/cql3/restrictions/statement_restrictions.hh +++ b/cql3/restrictions/statement_restrictions.hh @@ -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& 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); + + } } diff --git a/cql3/statements/modification_statement.cc b/cql3/statements/modification_statement.cc index 09dd310281..f276661212 100644 --- a/cql3/statements/modification_statement.cc +++ b/cql3/statements/modification_statement.cc @@ -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 diff --git a/cql3/statements/select_statement.cc b/cql3/statements/select_statement.cc index eaf0df29d3..eb744e4aed 100644 --- a/cql3/statements/select_statement.cc +++ b/cql3/statements/select_statement.cc @@ -2164,8 +2164,8 @@ select_statement::prepare_restrictions(data_dictionary::database db, restrictions::check_indexes do_check_indexes) { try { - return ::make_shared(db, schema, statement_type::SELECT, _where_clause, ctx, - selection->contains_only_static_columns(), for_view, allow_filtering, do_check_indexes); + return ::make_shared(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)); diff --git a/test/boost/statement_restrictions_test.cc b/test/boost/statement_restrictions_test.cc index 0c4ef8f8a4..6365299c19 100644 --- a/test/boost/statement_restrictions_test.cc +++ b/test/boost/statement_restrictions_test.cc @@ -30,7 +30,7 @@ query::clustering_row_ranges slice( const std::vector& 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,