-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Simplify predicates in PushDownFilter
optimizer rule
#16362
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
base: main
Are you sure you want to change the base?
Conversation
f12788d
to
fee2358
Compare
let new_predicates = simplify_predicates(predicate)?; | ||
if old_predicate_len != new_predicates.len() { | ||
let Some(new_predicate) = conjunction(new_predicates) else { | ||
return plan_err!("at least one expression exists"); |
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.
Can new_predicates
be empty?
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.
No, as long as the original filter's predicate is not empty, simplify_predicates
will keep at least one predicate.
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.
The caller of that function doesn't need to hard-code this assumption.
What if simplify_predicates
realizes that the only predicate is trivially true and can be removed (for example x = x
and we know x is not null).
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.
Also, currently simplify_predicates
doesn't have the ability, but it should have, make sense, I'll update it
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.
Updated in 883f562
let predicate = split_conjunction_owned(filter.predicate.clone()); | ||
let old_predicate_len = predicate.len(); | ||
let new_predicates = simplify_predicates(predicate)?; |
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.
new_predicates
operates on col comparison_operator literal
sometimes these are tied in conjuncts: a > -5 AND a < 5
or disjuncts: a < -5 OR a > 5
would it make sense to be able to process per-column predicates in both forms?
To do that we could have a function Expr -> captured per-column predicates and then be able to combine such functions on AND and on OR
This might be related https://github.com/trinodb/trino/blob/232916b75d415a5eb643cf922492eb8513d99aae/core/trino-main/src/main/java/io/trino/sql/planner/DomainTranslator.java#L365
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.
a > -5 AND a < 5
will be split to [a > -5
, a < 5
], it seems that the two split predicates can't be simplified, that is, we shoud keep the two.
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, but if I can have a < -5 OR a > 5
then maybe I can have a < -5 OR a > 5 OR a < -10 OR a > 10
. This is simplifiable.
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.
Okay, good point, we can do this as the following PR
fee2358
to
883f562
Compare
883f562
to
92d9658
Compare
PushDownFilter
optimizer rule
🤖 |
🤖: Benchmark completed Details
|
Which issue does this PR close?
Rationale for this change
This PR adds predicate simplification capabilities to the
PushDownFilter
optimizer rule. Currently, when filters contain redundant predicates (likex > 5 AND x > 6
), these are not simplified, leading to unnecessary work during query execution.The goal is to optimize filter predicates by removing redundant conditions and keeping only the most restrictive ones, which can improve query performance.
What changes are included in this PR?
New predicate simplification module (
simplify_predicates.rs
):x = 5 AND x = 6
becomesfalse
)Enhanced push_down_filter.rs:
simplify_predicates
before applying other optimizationsAre these changes tested?
20+ test cases in
simplify_predicates.slt
Are there any user-facing changes?