-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Implement physical optimizer rule for common subexpression elimination #12599
Comments
We have also added this issue to our todo's (though we likely won't be able to address it in the short term). It would be better to have this rule implemented directly in DataFusion. |
@peter-toth and several others have invested significant time making the CSE pass in the logical optimizer fast and efficient The logical rewrite code is here https://github.com/apache/datafusion/blob/2e274bfbdfc19f11b2951456bb2a48e88733c9bf/datafusion/optimizer/src/common_subexpr_eliminate.rs#L1-L0 It would be sweet somehow to factor out the CSE logic itself so it worked on both |
Thanks @alamb for pinging me! I was a bit busy lately, but I'm happy to look into this issue next week or so. |
Just a quick update that I've started working on this. Will try to submit a PR this week. |
Is your feature request related to a problem or challenge?
When running TPC-H q1 in Spark + DataFusion Comet, the expression
l_extendedprice#21 * (1 - l_discount#22)
appears twice in the query and currently gets evaluated twice. This could be optimized out so that it is only evaluated once. I was able to test this by manually rewriting the query.Original Query
Optimized Query
Timings (Original)
Timings (Optimized)
Describe the solution you'd like
I would like a physical optimizer rule in DataFusion for common subexpression elimination. IIRC, we already have a logical rule for doing this, but that does not help for projects that are using other query front ends and then mapping to DataFusion's physical plan.
An alternative option would be to implement this directly in Comet.
Describe alternatives you've considered
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: