You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
EPIC: use cp_solver framework to develop a more sophisticated predicate simplification #16511
Is your feature request related to a problem or challenge?
The predicates in filter can be variable, it's possible to use the cp_solver to simplify the predicates in filter, then reduce the computing cost for filter.
Describe the solution you'd like
We've done some basic simplification in #16362, we can make it a start to develop a more sophisticated rule to cover more cases
Describe alternatives you've considered
No response
Additional context
What I want to discuss:
Make it a new physical optimizer rule? Or add them to the current physical filter push down
Some filters, such as partition columns related predicates, will be fully pushed down scan, that is, we don't have such predicates in some FilterExec. How to capture this?
Make it a new physical optimizer rule? Or add them to the current physical filter push down
Do we need a phyiscal optimizer rule? My thought is that these optimizations can happen at the logical layer. At the phyiscal layer we do need some expression optimization, but primarily to deal with type casting to match the file schema, etc (i.e. #16530), expressions at this point should be already simplified from the logical layer and that doesn't really change except maybe in some edge cases which I'm not sure are worth dealing with.
Some filters, such as partition columns related predicates, will be fully pushed down scan, that is, we don't have such predicates in some FilterExec. How to capture this?
My thought is that these optimizations can happen at the logical layer
Yes, almost all DBs do the optimization in logical layer, but as @alamb said, we want to use the cp solver framework to make it general(cp solver is in the physical layer).
Even though the cp_solver is done at the physical layer, I think the overall simplification can still be done in an Optimizer that targets LogicalPlans -- much like the expression simplifier works, we would convert to a physical expr during planning:
Activity
adriangb commentedon Jun 24, 2025
Do we need a phyiscal optimizer rule? My thought is that these optimizations can happen at the logical layer. At the phyiscal layer we do need some expression optimization, but primarily to deal with type casting to match the file schema, etc (i.e. #16530), expressions at this point should be already simplified from the logical layer and that doesn't really change except maybe in some edge cases which I'm not sure are worth dealing with.
Not sure I understood this part
xudong963 commentedon Jun 26, 2025
Yes, almost all DBs do the optimization in logical layer, but as @alamb said, we want to use the cp solver framework to make it general(cp solver is in the physical layer).
In logical filter pushdown, the partition-related filters will be fully pushed down to scan(they are Exact), see code here:
https://github.com/apache/datafusion/blob/main/datafusion/optimizer/src/push_down_filter.rs#L1128-L1153
alamb commentedon Jun 26, 2025
Even though the cp_solver is done at the physical layer, I think the overall simplification can still be done in an Optimizer that targets
LogicalPlans-- much like the expression simplifier works, we would convert to a physical expr during planning:datafusion/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs
Lines 674 to 678 in 3649dc8