cql3: Use expression instead of _partition_key_restrictions in the remaining code
There are still some places that use partition_key_restrictions instead of _new_partition_key_restrictions in statement_restrictions. Change them to use the new representation Signed-off-by: Jan Ciolek <jan.ciolek@scylladb.com>
This commit is contained in:
@@ -861,7 +861,7 @@ void statement_restrictions::process_partition_key_restrictions(bool for_view, b
|
||||
// - Is it queriable without 2ndary index, which is always more efficient
|
||||
// If a component of the partition key is restricted by a relation, all preceding
|
||||
// components must have a EQ. Only the last partition key component can be in IN relation.
|
||||
if (has_token(_partition_key_restrictions->expression)) {
|
||||
if (has_token(_new_partition_key_restrictions)) {
|
||||
_is_key_range = true;
|
||||
} else if (expr::is_empty_restriction(_new_partition_key_restrictions)) {
|
||||
_is_key_range = true;
|
||||
@@ -1735,7 +1735,7 @@ bool token_known(const statement_restrictions& r) {
|
||||
bool statement_restrictions::need_filtering() const {
|
||||
using namespace expr;
|
||||
|
||||
if (_uses_secondary_indexing && has_token(_partition_key_restrictions->expression)) {
|
||||
if (_uses_secondary_indexing && has_token(_new_partition_key_restrictions)) {
|
||||
// If there is a token(p1, p2) restriction, no p1, p2 restrictions are allowed in the query.
|
||||
// All other restrictions must be on clustering or regular columns.
|
||||
int64_t non_pk_restrictions_count = _clustering_columns_restrictions->size();
|
||||
@@ -1847,11 +1847,11 @@ void statement_restrictions::prepare_indexed_global(const schema& idx_tbl_schema
|
||||
|
||||
const column_definition* token_column = &idx_tbl_schema.clustering_column_at(0);
|
||||
|
||||
if (has_token(_partition_key_restrictions->expression)) {
|
||||
if (has_token(_new_partition_key_restrictions)) {
|
||||
// When there is a token(p1, p2) >/</= ? restriction, it is not allowed to have restrictions on p1 or p2.
|
||||
// This means that p1 and p2 can have many different values (token is a hash, can have collisions).
|
||||
// Clustering prefix ends after token_restriction, all further restrictions have to be filtered.
|
||||
expr::expression token_restriction = replace_token(_partition_key_restrictions->expression, token_column);
|
||||
expr::expression token_restriction = replace_token(_new_partition_key_restrictions, token_column);
|
||||
_idx_tbl_ck_prefix = std::vector{std::move(token_restriction)};
|
||||
|
||||
return;
|
||||
|
||||
@@ -143,7 +143,7 @@ public:
|
||||
* otherwise.
|
||||
*/
|
||||
bool key_is_in_relation() const {
|
||||
return find(_partition_key_restrictions->expression, expr::oper_t::IN);
|
||||
return find(_new_partition_key_restrictions, expr::oper_t::IN);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -178,8 +178,8 @@ public:
|
||||
return _uses_secondary_indexing;
|
||||
}
|
||||
|
||||
::shared_ptr<partition_key_restrictions> get_partition_key_restrictions() const {
|
||||
return _partition_key_restrictions;
|
||||
const expr::expression& get_partition_key_restrictions() const {
|
||||
return _new_partition_key_restrictions;
|
||||
}
|
||||
|
||||
::shared_ptr<clustering_key_restrictions> get_clustering_columns_restrictions() const {
|
||||
@@ -187,7 +187,7 @@ public:
|
||||
}
|
||||
|
||||
bool has_token_restrictions() const {
|
||||
return has_token(_partition_key_restrictions->expression);
|
||||
return has_token(_new_partition_key_restrictions);
|
||||
}
|
||||
|
||||
// Checks whether the given column has an EQ restriction.
|
||||
@@ -261,11 +261,11 @@ private:
|
||||
* @param kind the column type
|
||||
* @return the <code>restrictions</code> for the specified type of columns
|
||||
*/
|
||||
::shared_ptr<restrictions> get_restrictions(column_kind kind) const {
|
||||
const expr::expression& get_restrictions(column_kind kind) const {
|
||||
switch (kind) {
|
||||
case column_kind::partition_key: return _partition_key_restrictions;
|
||||
case column_kind::clustering_key: return _clustering_columns_restrictions;
|
||||
default: return _nonprimary_key_restrictions;
|
||||
case column_kind::partition_key: return _new_partition_key_restrictions;
|
||||
case column_kind::clustering_key: return _new_clustering_columns_restrictions;
|
||||
default: return _new_nonprimary_key_restrictions;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -464,7 +464,7 @@ public:
|
||||
// If token restrictions are present in an indexed query, then all other restrictions need to be filtered.
|
||||
// A single token restriction can have multiple matching partition key values.
|
||||
// Because of this we can't create a clustering prefix with more than token restriction.
|
||||
|| (_uses_secondary_indexing && has_token(_partition_key_restrictions->expression));
|
||||
|| (_uses_secondary_indexing && has_token(_new_partition_key_restrictions));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -475,7 +475,7 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
auto&& restricted = get_restrictions(cdef->kind).get()->get_column_defs();
|
||||
auto restricted = expr::get_sorted_column_defs(get_restrictions(cdef->kind));
|
||||
return std::find(restricted.begin(), restricted.end(), cdef) != restricted.end();
|
||||
}
|
||||
|
||||
|
||||
@@ -388,9 +388,9 @@ modification_statement::process_where_clause(data_dictionary::database db, std::
|
||||
_has_regular_column_conditions = true;
|
||||
}
|
||||
}
|
||||
if (has_token(_restrictions->get_partition_key_restrictions()->expression)) {
|
||||
if (has_token(_restrictions->get_partition_key_restrictions())) {
|
||||
throw exceptions::invalid_request_exception(format("The token function cannot be used in WHERE clauses for UPDATE and DELETE statements: {}",
|
||||
to_string(_restrictions->get_partition_key_restrictions()->expression)));
|
||||
to_string(_restrictions->get_partition_key_restrictions())));
|
||||
}
|
||||
if (!_restrictions->get_non_pk_restriction().empty()) {
|
||||
auto column_names = ::join(", ", _restrictions->get_non_pk_restriction()
|
||||
|
||||
@@ -859,8 +859,8 @@ primary_key_select_statement::primary_key_select_statement(schema_ptr schema, ui
|
||||
if (_ks_sel == ks_selector::NONSYSTEM) {
|
||||
if (_restrictions->need_filtering() ||
|
||||
_restrictions->partition_key_restrictions_is_empty() ||
|
||||
(has_token(_restrictions->get_partition_key_restrictions()->expression) &&
|
||||
!find(_restrictions->get_partition_key_restrictions()->expression, expr::oper_t::EQ))) {
|
||||
(has_token(_restrictions->get_partition_key_restrictions()) &&
|
||||
!find(_restrictions->get_partition_key_restrictions(), expr::oper_t::EQ))) {
|
||||
_range_scan = true;
|
||||
if (!_parameters->bypass_cache())
|
||||
_range_scan_no_bypass_cache = true;
|
||||
@@ -1193,9 +1193,9 @@ query::partition_slice indexed_table_select_statement::get_partition_slice_for_g
|
||||
partition_slice_builder partition_slice_builder{*_view_schema};
|
||||
|
||||
if (!_restrictions->has_partition_key_unrestricted_components()) {
|
||||
auto single_pk_restrictions = dynamic_pointer_cast<restrictions::single_column_partition_key_restrictions>(_restrictions->get_partition_key_restrictions());
|
||||
bool pk_restrictions_is_single = !has_token(_restrictions->get_partition_key_restrictions());
|
||||
// Only EQ restrictions on base partition key can be used in an index view query
|
||||
if (single_pk_restrictions && single_pk_restrictions->is_all_eq()) {
|
||||
if (pk_restrictions_is_single && _restrictions->partition_key_restrictions_is_all_eq()) {
|
||||
partition_slice_builder.with_ranges(
|
||||
_restrictions->get_global_index_clustering_ranges(options, *_view_schema));
|
||||
} else if (_restrictions->has_token_restrictions()) {
|
||||
@@ -1945,10 +1945,10 @@ static bool needs_allow_filtering_anyway(
|
||||
return false;
|
||||
}
|
||||
const auto& ck_restrictions = *restrictions.get_clustering_columns_restrictions();
|
||||
const auto& pk_restrictions = *restrictions.get_partition_key_restrictions();
|
||||
const auto& pk_restrictions = restrictions.get_partition_key_restrictions();
|
||||
// Even if no filtering happens on the coordinator, we still warn about poor performance when partition
|
||||
// slice is defined but in potentially unlimited number of partitions (see #7608).
|
||||
if ((pk_restrictions.empty() || has_token(pk_restrictions.expression)) // Potentially unlimited partitions.
|
||||
if ((expr::is_empty_restriction(pk_restrictions) || has_token(pk_restrictions)) // Potentially unlimited partitions.
|
||||
&& !ck_restrictions.empty() // Slice defined.
|
||||
&& !restrictions.uses_secondary_indexing()) { // Base-table is used. (Index-table use always limits partitions.)
|
||||
if (strict_allow_filtering == flag_t::WARN) {
|
||||
|
||||
@@ -231,7 +231,7 @@ void stats::register_stats() {
|
||||
}
|
||||
|
||||
bool partition_key_matches(const schema& base, const view_info& view, const dht::decorated_key& key) {
|
||||
const auto r = view.select_statement().get_restrictions()->get_partition_key_restrictions();
|
||||
const cql3::expr::expression& pk_restrictions = view.select_statement().get_restrictions()->get_partition_key_restrictions();
|
||||
std::vector<bytes> exploded_pk = key.key().explode();
|
||||
std::vector<bytes> exploded_ck;
|
||||
std::vector<const column_definition*> pk_columns;
|
||||
@@ -245,7 +245,7 @@ bool partition_key_matches(const schema& base, const view_info& view, const dht:
|
||||
auto dummy_options = cql3::query_options({ });
|
||||
// FIXME: pass nullptrs for some of theses dummies
|
||||
return cql3::expr::is_satisfied_by(
|
||||
r->expression,
|
||||
pk_restrictions,
|
||||
cql3::expr::evaluation_inputs{
|
||||
.partition_key = &exploded_pk,
|
||||
.clustering_key = &exploded_ck,
|
||||
|
||||
Reference in New Issue
Block a user