Skip to content

Commit

Permalink
cql3: fix fetching clustering key columns for filtering
Browse files Browse the repository at this point in the history
When a column is not present in the select clause, but used for
filtering, it usually needs to be fetched from replicas.
Sometimes it can be avoided, e.g. if primary key columns form a valid
prefix - then, they will be optimized out before filtering itself.
However, clustering key prefix can only be qualified for this
optimization if the whole partition key is restricted - otherwise
the clustering columns still need to be present for filtering.

Fixes scylladb#4541
  • Loading branch information
psarna committed Jun 12, 2019
1 parent e32b4a3 commit d04d7bd
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cql3/restrictions/statement_restrictions.cc
Expand Up @@ -392,8 +392,9 @@ std::vector<const column_definition*> statement_restrictions::get_column_defs_fo
}
}
}
if (_clustering_columns_restrictions->needs_filtering(*_schema)) {
column_id first_filtering_id = _schema->clustering_key_columns().begin()->id +
const bool pk_has_unrestricted_components = _partition_key_restrictions->has_unrestricted_components(*_schema);
if (pk_has_unrestricted_components || _clustering_columns_restrictions->needs_filtering(*_schema)) {
column_id first_filtering_id = pk_has_unrestricted_components ? 0 : _schema->clustering_key_columns().begin()->id +
_clustering_columns_restrictions->num_prefix_columns_that_need_not_be_filtered();
for (auto&& cdef : _clustering_columns_restrictions->get_column_defs()) {
if (cdef->id >= first_filtering_id && !column_uses_indexing(cdef)) {
Expand Down

0 comments on commit d04d7bd

Please sign in to comment.