cql3: statement_restrictions: avoid expression's default constructor when classifying restrictions

We have some gnarly code that classifies restrictions by the column
they restrict. This uses std::unordered_map::operatorp[], which uses
the value's default constructor. This happens to be "expression", and
as we're about to remove the default constructor, this won't do.

Fix by using try_emplace(), which makes the code nicer and more
efficient. It could be further improved, but it's better to demolish it
instead.
This commit is contained in:
Avi Kivity
2023-07-14 15:52:03 +03:00
parent 61be544431
commit f94eb708e9

View File

@@ -120,11 +120,9 @@ static std::vector<expr::expression> extract_partition_range(
auto s = &cv;
with_current_binary_operator(*this, [&] (const binary_operator& b) {
if (s->col->is_partition_key() && (b.op == oper_t::EQ || b.op == oper_t::IN)) {
const auto found = single_column.find(s->col);
if (found == single_column.end()) {
single_column[s->col] = b;
} else {
found->second = make_conjunction(std::move(found->second), b);
const auto [it, inserted] = single_column.try_emplace(s->col, b);
if (!inserted) {
it->second = make_conjunction(std::move(it->second), b);
}
}
});
@@ -139,11 +137,9 @@ static std::vector<expr::expression> extract_partition_range(
with_current_binary_operator(*this, [&] (const binary_operator& b) {
if (cval.col->is_partition_key() && (b.op == oper_t::EQ || b.op == oper_t::IN)) {
const auto found = single_column.find(cval.col);
if (found == single_column.end()) {
single_column[cval.col] = b;
} else {
found->second = make_conjunction(std::move(found->second), b);
const auto [it, inserted] = single_column.try_emplace(cval.col, b);
if (!inserted) {
it->second = make_conjunction(std::move(it->second), b);
}
}
});
@@ -247,11 +243,9 @@ static std::vector<expr::expression> extract_clustering_prefix_restrictions(
auto s = &cv;
with_current_binary_operator(*this, [&] (const binary_operator& b) {
if (s->col->is_clustering_key()) {
const auto found = single.find(s->col);
if (found == single.end()) {
single[s->col] = b;
} else {
found->second = make_conjunction(std::move(found->second), b);
const auto [it, inserted] = single.try_emplace(s->col, b);
if (!inserted) {
it->second = make_conjunction(std::move(it->second), b);
}
}
});
@@ -262,11 +256,9 @@ static std::vector<expr::expression> extract_clustering_prefix_restrictions(
with_current_binary_operator(*this, [&] (const binary_operator& b) {
if (cval.col->is_clustering_key()) {
const auto found = single.find(cval.col);
if (found == single.end()) {
single[cval.col] = b;
} else {
found->second = make_conjunction(std::move(found->second), b);
const auto [it, inserted] = single.try_emplace(cval.col, b);
if (!inserted) {
it->second = make_conjunction(std::move(it->second), b);
}
}
});