cql3: expr: convert is_satisfied_by() signature to evaluation_inputs

Callers are converted, but the internals are kept using the old
conventions until more APIs are converted.

Although the new API allows passing no query_options, the view code
keeps passing dummy query_options and improvement is left as a FIXME.
This commit is contained in:
Avi Kivity
2022-06-12 12:53:44 +03:00
parent 7a9b645d64
commit 4b715226fe
4 changed files with 74 additions and 19 deletions

View File

@@ -795,14 +795,10 @@ expression make_conjunction(expression a, expression b) {
return conjunction{std::move(children)};
}
bool is_satisfied_by(
const expression& restr,
const std::vector<bytes>& partition_key, const std::vector<bytes>& clustering_key,
const query::result_row_view& static_row, const query::result_row_view* row,
const selection& selection, const query_options& options) {
const auto regulars = get_non_pk_values(selection, static_row, row);
bool is_satisfied_by(const expression& restr, const evaluation_inputs& inputs) {
const auto regulars = get_non_pk_values(*inputs.selection, *inputs.static_row, inputs.row);
return is_satisfied_by(
restr, {options, row_data_from_partition_slice{partition_key, clustering_key, regulars, selection}});
restr, {*inputs.options, row_data_from_partition_slice{*inputs.partition_key, *inputs.clustering_key, regulars, *inputs.selection}});
}
template<typename T>

View File

@@ -457,12 +457,10 @@ struct evaluation_inputs {
const query_options* options = nullptr;
};
/// True iff restr is satisfied with respect to the row provided from a partition slice.
/// True iff restr evaluates to true, given these inputs
extern bool is_satisfied_by(
const expression& restr,
const std::vector<bytes>& partition_key, const std::vector<bytes>& clustering_key,
const query::result_row_view& static_row, const query::result_row_view* row,
const selection::selection&, const query_options&);
const expression& restr, const evaluation_inputs& inputs);
/// A set of discrete values.
using value_list = std::vector<managed_bytes>; // Sorted and deduped using value comparator.

View File

@@ -428,7 +428,14 @@ bool result_set_builder::restrictions_filter::do_filter(const selection& selecti
clustering_key_prefix ckey = clustering_key_prefix::from_exploded(clustering_key);
return expr::is_satisfied_by(
clustering_columns_restrictions->expression,
partition_key, clustering_key, static_row, row, selection, _options);
expr::evaluation_inputs{
.partition_key = &partition_key,
.clustering_key = &clustering_key,
.static_row = &static_row,
.row = row,
.selection = &selection,
.options = &_options,
});
}
auto static_row_iterator = static_row.iterator();
@@ -448,7 +455,15 @@ bool result_set_builder::restrictions_filter::do_filter(const selection& selecti
}
restrictions::single_column_restriction& restriction = *restr_it->second;
bool regular_restriction_matches = expr::is_satisfied_by(
restriction.expression, partition_key, clustering_key, static_row, row, selection, _options);
restriction.expression,
expr::evaluation_inputs{
.partition_key = &partition_key,
.clustering_key = &clustering_key,
.static_row = &static_row,
.row = row,
.selection = &selection,
.options = &_options,
});
if (!regular_restriction_matches) {
_current_static_row_does_not_match = (cdef->kind == column_kind::static_column);
return false;
@@ -466,7 +481,15 @@ bool result_set_builder::restrictions_filter::do_filter(const selection& selecti
}
restrictions::single_column_restriction& restriction = *restr_it->second;
if (!expr::is_satisfied_by(
restriction.expression, partition_key, clustering_key, static_row, row, selection, _options)) {
restriction.expression,
expr::evaluation_inputs{
.partition_key = &partition_key,
.clustering_key = &clustering_key,
.static_row = &static_row,
.row = row,
.selection = &selection,
.options = &_options,
})) {
_current_partition_key_does_not_match = true;
return false;
}
@@ -486,7 +509,15 @@ bool result_set_builder::restrictions_filter::do_filter(const selection& selecti
}
restrictions::single_column_restriction& restriction = *restr_it->second;
if (!expr::is_satisfied_by(
restriction.expression, partition_key, clustering_key, static_row, row, selection, _options)) {
restriction.expression,
expr::evaluation_inputs{
.partition_key = &partition_key,
.clustering_key = &clustering_key,
.static_row = &static_row,
.row = row,
.selection = &selection,
.options = &_options,
})) {
return false;
}
}

View File

@@ -242,8 +242,18 @@ bool partition_key_matches(const schema& base, const view_info& view, const dht:
auto selection = cql3::selection::selection::for_columns(base.shared_from_this(), pk_columns);
uint64_t zero = 0;
auto dummy_row = query::result_row_view(ser::qr_row_view{simple_memory_input_stream(reinterpret_cast<const char*>(&zero), 8)});
auto dummy_options = cql3::query_options({ });
// FIXME: pass nullptrs for some of theses dummies
return cql3::expr::is_satisfied_by(
r->expression, exploded_pk, exploded_ck, dummy_row, &dummy_row, *selection, cql3::query_options({ }));
r->expression,
cql3::expr::evaluation_inputs{
.partition_key = &exploded_pk,
.clustering_key = &exploded_ck,
.static_row = &dummy_row,
.row = &dummy_row,
.selection = selection.get(),
.options = &dummy_options,
});
}
bool clustering_prefix_matches(const schema& base, const view_info& view, const partition_key& key, const clustering_key_prefix& ck) {
@@ -258,8 +268,18 @@ bool clustering_prefix_matches(const schema& base, const view_info& view, const
auto selection = cql3::selection::selection::for_columns(base.shared_from_this(), ck_columns);
uint64_t zero = 0;
auto dummy_row = query::result_row_view(ser::qr_row_view{simple_memory_input_stream(reinterpret_cast<const char*>(&zero), 8)});
auto dummy_options = cql3::query_options({ });
// FIXME: pass nullptrs for some of theses dummies
return cql3::expr::is_satisfied_by(
r->expression, exploded_pk, exploded_ck, dummy_row, &dummy_row, *selection, cql3::query_options({ }));
r->expression,
cql3::expr::evaluation_inputs{
.partition_key = &exploded_pk,
.clustering_key = &exploded_ck,
.static_row = &dummy_row,
.row = &dummy_row,
.selection = selection.get(),
.options = &dummy_options,
});
}
bool may_be_affected_by(const schema& base, const view_info& view, const dht::decorated_key& key, const rows_entry& update) {
@@ -320,8 +340,18 @@ public:
return boost::algorithm::all_of(
_view.select_statement().get_restrictions()->get_non_pk_restriction() | boost::adaptors::map_values,
[&] (auto&& r) {
// FIXME: pass dummy_options as nullptr
auto dummy_options = cql3::query_options({});
return cql3::expr::is_satisfied_by(
r->expression, _pk, ck, static_row, &row, *_selection, cql3::query_options({ }));
r->expression,
cql3::expr::evaluation_inputs{
.partition_key = &_pk,
.clustering_key = &ck,
.static_row = &static_row,
.row = &row,
.selection = _selection.get(),
.options = &dummy_options,
});
}
);
}