Skip to content

Commit

Permalink
Apply filter on neutral element (#1842)
Browse files Browse the repository at this point in the history
The neutral element can still get filtered out if a constant-expression `FILTER` clause is present. This PR correctly applies this filter. This corrects the beahviors for queries such as 
```
ASK { FILTER (1 < 0) }
```
Which should return `false`, as the filter filters out all possible results, even if they have no bound variables.
  • Loading branch information
RobinTF authored Mar 3, 2025
1 parent 46948b2 commit 01f91a6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/engine/QueryPlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,10 @@ std::vector<QueryPlanner::SubtreePlan> QueryPlanner::optimize(
if (candidatePlans.at(0).empty()) {
// This happens if either graph pattern is an empty group,
// or it only consists of a MINUS clause (which then has no effect).
return {makeSubtreePlan<NeutralElementOperation>(_qec)};
std::vector neutralPlans{makeSubtreePlan<NeutralElementOperation>(_qec)};
// Neutral element can potentially still get filtered out
applyFiltersIfPossible<true>(neutralPlans, rootPattern->_filters);
return neutralPlans;
}
return candidatePlans[0];
}
Expand Down
12 changes: 12 additions & 0 deletions test/QueryPlannerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2981,3 +2981,15 @@ TEST(QueryPlanner, Exists) {
"GRAPH ?g { ?u ?v ?c}}}",
filter);
}

// _____________________________________________________________________________
TEST(QueryPlanner, FilterOnNeutralElement) {
h::expect("SELECT * { FILTER(false) }",
h::Filter("false", h::NeutralElement()));
h::expect("SELECT * { FILTER(true) }",
h::Filter("true", h::NeutralElement()));

h::expect("SELECT * { { SELECT * WHERE { FILTER(false) } } VALUES ?x { 1 } }",
h::CartesianProductJoin(h::Filter("false", h::NeutralElement()),
h::ValuesClause("VALUES (?x) { (1) }")));
}

0 comments on commit 01f91a6

Please sign in to comment.