mirror of
https://github.com/scylladb/scylladb.git
synced 2026-06-02 21:17:01 +00:00
cql3: statement_restrictions: simplify find_idx to return only the index
The expression returned as the second element of find_idx()'s pair was stored in view_indexed_table_select_statement::_used_index_restrictions but never read — dead code. Simplify find_idx() to return just the optional<index>, and remove the dead member and constructor parameter from view_indexed_table_select_statement. The now unused _idx_restrictions is also removed.
This commit is contained in:
@@ -1186,7 +1186,6 @@ statement_restrictions::statement_restrictions(private_tag,
|
||||
if (idx_result.index) {
|
||||
_idx_opt = std::make_unique<secondary_index::index>(std::move(*idx_result.index));
|
||||
}
|
||||
_idx_restrictions = std::move(idx_result.restrictions);
|
||||
_idx_column_predicates = std::move(idx_result.indexed_column_predicates);
|
||||
}
|
||||
|
||||
@@ -1401,9 +1400,9 @@ static do_find_idx_result do_find_idx(
|
||||
return {chosen_index, chosen_index_restrictions, std::move(chosen_index_predicates)};
|
||||
}
|
||||
|
||||
std::pair<std::optional<secondary_index::index>, expr::expression>
|
||||
std::optional<secondary_index::index>
|
||||
statement_restrictions::find_idx(const secondary_index::secondary_index_manager& sim) const {
|
||||
return {_idx_opt ? std::optional<secondary_index::index>(*_idx_opt) : std::nullopt, _idx_restrictions};
|
||||
return _idx_opt ? std::optional<secondary_index::index>(*_idx_opt) : std::nullopt;
|
||||
}
|
||||
|
||||
bool statement_restrictions::has_eq_restriction_on_column(const column_definition& column) const {
|
||||
|
||||
@@ -227,7 +227,6 @@ private:
|
||||
std::vector<const column_definition*> _column_defs_for_filtering;
|
||||
schema_ptr _view_schema;
|
||||
std::unique_ptr<secondary_index::index> _idx_opt;
|
||||
expr::expression _idx_restrictions = expr::conjunction({});
|
||||
std::vector<predicate> _idx_column_predicates; ///< Predicates for the chosen index's target column.
|
||||
get_partition_key_ranges_fn_t _get_partition_key_ranges_fn;
|
||||
get_clustering_bounds_fn_t _get_clustering_bounds_fn;
|
||||
@@ -344,9 +343,8 @@ public:
|
||||
* Determines the index to be used with the restriction.
|
||||
* @param db - the data_dictionary::database context (for extracting index manager)
|
||||
* @return If an index can be used, an optional containing this index, otherwise an empty optional.
|
||||
* In case the index is returned, second parameter returns the index restriction it uses.
|
||||
*/
|
||||
std::pair<std::optional<secondary_index::index>, expr::expression> find_idx(const secondary_index::secondary_index_manager& sim) const;
|
||||
std::optional<secondary_index::index> find_idx(const secondary_index::secondary_index_manager& sim) const;
|
||||
|
||||
/**
|
||||
* Checks if the partition key has some unrestricted components.
|
||||
|
||||
@@ -1037,7 +1037,7 @@ view_indexed_table_select_statement::prepare(data_dictionary::database db,
|
||||
{
|
||||
auto cf = db.find_column_family(schema);
|
||||
auto& sim = cf.get_index_manager();
|
||||
auto [index_opt, used_index_restrictions] = restrictions->find_idx(sim);
|
||||
auto index_opt = restrictions->find_idx(sim);
|
||||
|
||||
if (!index_opt) {
|
||||
throw std::runtime_error("No index found.");
|
||||
@@ -1063,7 +1063,6 @@ view_indexed_table_select_statement::prepare(data_dictionary::database db,
|
||||
std::move(per_partition_limit),
|
||||
stats,
|
||||
*index_opt,
|
||||
std::move(used_index_restrictions),
|
||||
view_schema,
|
||||
std::move(attrs));
|
||||
|
||||
@@ -1080,12 +1079,10 @@ view_indexed_table_select_statement::view_indexed_table_select_statement(schema_
|
||||
std::optional<expr::expression> per_partition_limit,
|
||||
cql_stats &stats,
|
||||
const secondary_index::index& index,
|
||||
expr::expression used_index_restrictions,
|
||||
schema_ptr view_schema,
|
||||
std::unique_ptr<attributes> attrs)
|
||||
: select_statement{schema, bound_terms, parameters, selection, restrictions, group_by_cell_indices, is_reversed, ordering_comparator, limit, per_partition_limit, stats, std::move(attrs)}
|
||||
, _index{index}
|
||||
, _used_index_restrictions(std::move(used_index_restrictions))
|
||||
, _view_schema(view_schema)
|
||||
{
|
||||
throwing_assert(_view_schema);
|
||||
|
||||
@@ -186,7 +186,6 @@ public:
|
||||
|
||||
class view_indexed_table_select_statement : public select_statement {
|
||||
secondary_index::index _index;
|
||||
expr::expression _used_index_restrictions;
|
||||
schema_ptr _view_schema;
|
||||
noncopyable_function<dht::partition_range_vector(const query_options&)> _get_partition_ranges_for_posting_list;
|
||||
noncopyable_function<query::partition_slice(const query_options&)> _get_partition_slice_for_posting_list;
|
||||
@@ -219,7 +218,6 @@ public:
|
||||
std::optional<expr::expression> per_partition_limit,
|
||||
cql_stats &stats,
|
||||
const secondary_index::index& index,
|
||||
expr::expression used_index_restrictions,
|
||||
schema_ptr view_schema,
|
||||
std::unique_ptr<cql3::attributes> attrs);
|
||||
|
||||
|
||||
@@ -414,7 +414,7 @@ SEASTAR_TEST_CASE(index_selection) {
|
||||
/*for_view=*/false,
|
||||
/*allow_filtering=*/true,
|
||||
restrictions::check_indexes::yes);
|
||||
auto [idx, restrictions_expr] = sr->find_idx(sim);
|
||||
auto idx = sr->find_idx(sim);
|
||||
return {where_clause,
|
||||
idx ? std::optional(idx->metadata().name()) : std::nullopt,
|
||||
sr->uses_secondary_indexing(),
|
||||
@@ -897,7 +897,7 @@ SEASTAR_TEST_CASE(combinatorial_restrictions) {
|
||||
ctx_msg("has_eq_restriction_on_column(fs)"));
|
||||
|
||||
// --- Index selection ---
|
||||
auto [idx_opt, idx_expr] = sr->find_idx(sim);
|
||||
auto idx_opt = sr->find_idx(sim);
|
||||
|
||||
// Determine expected index. The scoring algorithm:
|
||||
// - do_find_idx iterates _index_restrictions (PK group, then
|
||||
|
||||
Reference in New Issue
Block a user