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.
This commit is contained in:
Avi Kivity
2026-03-15 12:20:06 +02:00
parent b0c5eed384
commit 44b18f3399

View File

@@ -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<on_column>(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<expr::tuple_constructor>(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()));
}