From 44b18f3399b22cf05abbff0122fa84319d3e45d3 Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Sun, 15 Mar 2026 12:20:06 +0200 Subject: [PATCH] cql3: statement_restrictions: convert single-column branch to use predicate properties In the single-column partition-key and clustering-key sub-branches, replace direct binary_operator field inspections with pre-computed predicate booleans: !pred.equality && !pred.is_in instead of restr.op != EQ && restr.op != IN, pred.is_in instead of find(restr, IN), and pred.is_slice instead of has_slice(restr). Also fix a leftover restr.order in the multi-column branch error message. --- cql3/restrictions/statement_restrictions.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cql3/restrictions/statement_restrictions.cc b/cql3/restrictions/statement_restrictions.cc index 12d84ffc75..60d85a624e 100644 --- a/cql3/restrictions/statement_restrictions.cc +++ b/cql3/restrictions/statement_restrictions.cc @@ -1426,7 +1426,7 @@ statement_restrictions::statement_restrictions(private_tag, static auto order2str = [](auto o) { return o == expr::comparison_order::cql ? "plain" : "SCYLLA_CLUSTERING_BOUND"; }; throw exceptions::invalid_request_exception( format("Invalid combination of restrictions ({} / {})", - order2str(other_slice->order), order2str(restr.order))); + order2str(other_slice->order), order2str(pred.order))); } // Here check that there aren't two < <= or two > and >= @@ -1467,7 +1467,7 @@ statement_restrictions::statement_restrictions(private_tag, const column_definition* def = std::get(pred.on).column; if (def->is_partition_key()) { // View definition allows PK slices, because it's not a performance problem. - if (restr.op != expr::oper_t::EQ && restr.op != expr::oper_t::IN && !allow_filtering && !for_view) { + if (!pred.equality && !pred.is_in && !allow_filtering && !for_view) { throw exceptions::invalid_request_exception( "Only EQ and IN relation are supported on the partition key " "(unless you use the token() function or ALLOW FILTERING)"); @@ -1483,7 +1483,7 @@ statement_restrictions::statement_restrictions(private_tag, } _partition_key_restrictions = expr::make_conjunction(_partition_key_restrictions, restr); - _partition_range_is_simple &= !find(restr, expr::oper_t::IN); + _partition_range_is_simple &= !pred.is_in; } else if (def->is_clustering_key()) { if (find_binop(_clustering_columns_restrictions, [] (const expr::binary_operator& b) { return expr::is(b.lhs); @@ -1502,7 +1502,7 @@ statement_restrictions::statement_restrictions(private_tag, } if (schema->position(*new_column) < schema->position(*last_column)) { - if (has_slice(restr)) { + if (pred.is_slice) { throw exceptions::invalid_request_exception(format("PRIMARY KEY column \"{}\" cannot be restricted (preceding column \"{}\" is restricted by a non-EQ relation)", last_column->name_as_text(), new_column->name_as_text())); }