diff --git a/cql3/restrictions/statement_restrictions.cc b/cql3/restrictions/statement_restrictions.cc index 535b34a138a7..f74de4e9ba14 100644 --- a/cql3/restrictions/statement_restrictions.cc +++ b/cql3/restrictions/statement_restrictions.cc @@ -392,8 +392,9 @@ std::vector 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)) {