-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unify and embed multiple filters that operate on the same property #2055
base: master
Are you sure you want to change the base?
Conversation
1af2133
to
640ce88
Compare
Rewriting the Cypher AST tree to combine multiple filters into a range Insert range filter into range scans
640ce88
to
3c1c82f
Compare
@@ -251,6 +252,13 @@ BINARY_OPERATOR_VISIT(SubscriptOperator, "Subscript"); | |||
|
|||
#undef BINARY_OPERATOR_VISIT | |||
|
|||
void ExpressionPrettyPrinter::Visit(RangeOperator &op) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we reach this code/see its effect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is used when outputting the plan as a JSON.
The JSON is sent as part of the summary when running an EXPLAIN query.
Query (with index):
EXPLAIN MATCH (n:l) WHERE 1 < n.p < 10 RETURN n;
Explain query result:
+---------------------------------------------+
| QUERY PLAN |
+---------------------------------------------+
| " * Produce {n}" |
| " * ScanAllByLabelPropertyRange (n :l {p})" |
| " * Once" |
+---------------------------------------------+
JSON:
"explain": {
"input":{
"input":{
"name":"Once"
},
"label":"l",
"lower_bound":{
"type":"exclusive",
"value":"(ParameterLookup 7)"
},
"name":"ScanAllByLabelPropertyRange",
"output_symbol":"n",
"property":"p",
"upper_bound":{
"type":"exclusive",
"value":"(ParameterLookup 13)"
}
}
}
src/query/plan/preprocess.cpp
Outdated
@@ -184,7 +186,8 @@ void AddExpansionsToMatching(std::vector<Expansion> &expansions, Matching &match | |||
} | |||
} | |||
|
|||
auto SplitExpressionOnAnd(Expression *expression) { | |||
template <typename F1, typename F2> | |||
void SplitExpressionOnAnd(Expression *expression, F1 &&if_cb, F2 &&else_cb) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only two usages...inline into both places and refactor them to have simple implementations. The generic callbacks reduce readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
@@ -368,6 +369,12 @@ class ReturnBodyContext : public HierarchicalTreeVisitor { | |||
|
|||
#undef VISIT_BINARY_OPERATOR | |||
|
|||
bool PostVisit(RangeOperator &op) override { | |||
bool res = op.expr1_->Accept(*this); | |||
res |= op.expr2_->Accept(*this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does 2nd Accept need to be visited?
Can be do a short-cutting ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to check both branches.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the expression a < x < b
, a
and b
do not have to be literals and thus need to be checked.
Quality Gate passedIssues Measures |
Description
A query like
MATCH(n) WHERE n.p > 10 AND n.p < 20 RETURN n;
will generate a tree with 2 independent filters (
n.p > 10
andn.p < 20
).This becomes a problem when we come to our optimizer.
The optimizer tries to embed filters into range scans. The optimizer will embed one filter, but not the other. It limits the scans to a single filter, so only the upper or lower bound gets embedded.
This PR tries to introduce a new operator RangeOperator.
It should fix this problem and generate a single filter with a lower and upper bound, which gets correctly inserted into a ranged scan.
The operator is not generated by the
CypherMainVisitor
but later as part of the tree rewrite. This is so other optimizations that move filters around can get picked up and potentially combine filters from different parts of the query into a single range.[master < Task] PR
Documentation checklist