cql3: expr: push is_satisfied_by regular and static column extraction to callers

is_satisfied_by() rearranges the static and regular columns from
query::result_row_view form (which is a use-once iterator) to
std::vector<managed_bytes_opt> (which uses the standard value
representation, and allows random access which expression
evaluation needs). Doing it in is_saitisfied_by() means that it is
done every time an expression is evaluated, which is wasteful. It's
also done even if the expression doesn't need it at all.

Push it out to callers, which already eliminates some calls.

We still pass cql3::expr::selection, which is a layering violation,
but that is left to another time.

Note that in view.cc's check_if_matches(), we should have been
able to move static_and_regular_columns calculation outside the
loop. However, we get crashes if we do. This is likely due to a
preexisting bug (which the zero iterations loop avoids). However,
in selection.cc, we are able to avoid the computation when the code
claims it is only handling partition keys or clustering keys.
This commit is contained in:
Avi Kivity
2022-06-12 13:22:39 +03:00
parent 4b715226fe
commit c80999fab4
4 changed files with 27 additions and 19 deletions

View File

@@ -249,8 +249,7 @@ bool partition_key_matches(const schema& base, const view_info& view, const dht:
cql3::expr::evaluation_inputs{
.partition_key = &exploded_pk,
.clustering_key = &exploded_ck,
.static_row = &dummy_row,
.row = &dummy_row,
.static_and_regular_columns = nullptr, // partition key filtering only
.selection = selection.get(),
.options = &dummy_options,
});
@@ -267,7 +266,6 @@ 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(
@@ -275,8 +273,7 @@ bool clustering_prefix_matches(const schema& base, const view_info& view, const
cql3::expr::evaluation_inputs{
.partition_key = &exploded_pk,
.clustering_key = &exploded_ck,
.static_row = &dummy_row,
.row = &dummy_row,
.static_and_regular_columns = nullptr, // clustering key only filtering here
.selection = selection.get(),
.options = &dummy_options,
});
@@ -340,6 +337,8 @@ public:
return boost::algorithm::all_of(
_view.select_statement().get_restrictions()->get_non_pk_restriction() | boost::adaptors::map_values,
[&] (auto&& r) {
// FIXME: move outside all_of(). However, crashes.
auto static_and_regular_columns = cql3::expr::get_non_pk_values(*_selection, static_row, &row);
// FIXME: pass dummy_options as nullptr
auto dummy_options = cql3::query_options({});
return cql3::expr::is_satisfied_by(
@@ -347,8 +346,7 @@ public:
cql3::expr::evaluation_inputs{
.partition_key = &_pk,
.clustering_key = &ck,
.static_row = &static_row,
.row = &row,
.static_and_regular_columns = &static_and_regular_columns,
.selection = _selection.get(),
.options = &dummy_options,
});