Compare commits

...

2 Commits

Author SHA1 Message Date
antoniofilipovic
2bf635c119 fix bug 2023-11-23 16:02:59 +01:00
antoniofilipovic
c4c763d281 add rule based planner filter info fix 2023-11-23 15:40:58 +01:00
2 changed files with 10 additions and 5 deletions

View File

@@ -514,16 +514,20 @@ bool HasBoundFilterSymbols(const std::unordered_set<Symbol> &bound_symbols, cons
[&bound_symbols](const auto &symbol) { return bound_symbols.find(symbol) != bound_symbols.end(); });
}
Expression *ExtractFilters(const std::unordered_set<Symbol> &bound_symbols, Filters &filters, AstStorage &storage) {
Expression *ExtractFilters(const std::unordered_set<Symbol> &bound_symbols, Filters &filters, AstStorage &storage,
Filters &all_filters) {
Expression *filter_expr = nullptr;
std::vector<FilterInfo> and_joinable_filters{};
for (auto filters_it = filters.begin(); filters_it != filters.end();) {
if (HasBoundFilterSymbols(bound_symbols, *filters_it)) {
and_joinable_filters.emplace_back(*filters_it);
filter_expr = impl::BoolJoin<AndOperator>(storage, filter_expr, filters_it->expression);
filters_it = filters.erase(filters_it);
} else {
filters_it++;
}
}
all_filters.SetFilters(std::move(and_joinable_filters));
return filter_expr;
}

View File

@@ -80,7 +80,7 @@ namespace impl {
// Iterates over `Filters` joining them in one expression via
// `AndOperator` if symbols they use are bound.. All the joined filters are
// removed from `Filters`.
Expression *ExtractFilters(const std::unordered_set<Symbol> &, Filters &, AstStorage &);
Expression *ExtractFilters(const std::unordered_set<Symbol> &, Filters &, AstStorage &, Filters &);
/// Checks if the filters has all the bound symbols to be included in the current part of the query
bool HasBoundFilterSymbols(const std::unordered_set<Symbol> &bound_symbols, const FilterInfo &filter);
@@ -725,8 +725,9 @@ class RuleBasedPlanner {
// Join regular filters with lambda filter expression, so that they
// are done inline together. Semantic analysis should guarantee that
// lambda filtering uses bound symbols.
Filters all_filters;
filter_lambda.expression = impl::BoolJoin<AndOperator>(
storage, impl::ExtractFilters(bound_symbols, filters, storage), edge->filter_lambda_.expression);
storage, impl::ExtractFilters(bound_symbols, filters, storage, all_filters), edge->filter_lambda_.expression);
// At this point it's possible we have leftover filters for inline
// filtering (they use the inner symbols. If they were not collected,
// we have to remove them manually because no other filter-extraction
@@ -862,9 +863,9 @@ class RuleBasedPlanner {
std::unique_ptr<LogicalOperator> GenFilters(std::unique_ptr<LogicalOperator> last_op,
const std::unordered_set<Symbol> &bound_symbols, Filters &filters,
AstStorage &storage, const SymbolTable &symbol_table) {
auto all_filters = filters;
Filters all_filters{};
auto pattern_filters = ExtractPatternFilters(filters, symbol_table, storage, bound_symbols);
auto *filter_expr = impl::ExtractFilters(bound_symbols, filters, storage);
auto *filter_expr = impl::ExtractFilters(bound_symbols, filters, storage, all_filters);
if (filter_expr) {
last_op =