Rewrite SUM(expr + scalar) --> SUM(expr) + scalar*COUNT(expr) #20749
Draft
alamb wants to merge 3 commits intoapache:mainfrom
Draft
Rewrite SUM(expr + scalar) --> SUM(expr) + scalar*COUNT(expr) #20749alamb wants to merge 3 commits intoapache:mainfrom
SUM(expr + scalar) --> SUM(expr) + scalar*COUNT(expr) #20749alamb wants to merge 3 commits intoapache:mainfrom
Conversation
4 tasks
a9d1598 to
c20bf1e
Compare
Contributor
Author
|
run benchmark clickbench_partitioned |
1 similar comment
Contributor
Author
|
run benchmark clickbench_partitioned |
|
🤖 |
567eab3 to
7491c4d
Compare
|
🤖: Benchmark completed Details
|
|
🤖 |
7 tasks
|
🤖: Benchmark completed Details
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Draft until:
Which issue does this PR close?
SUM(..)clauses #15524SUM(expr + scalar)-->SUM(expr) + scalar*COUNT(expr)#20665Rationale for this change
I want DataFusion to be the fastest parquet engine on ClickBench. One of the queries where DataFusion is significantly slower is Query 29 which has a very strange pattern of many aggregate functions that are offset by a constant:
datafusion/benchmarks/queries/clickbench/queries/q29.sql
Line 4 in 0ca9d65
This is not a pattern I have ever seen in a real query, but it seems like the engine currently at the top of the ClickBench leaderboard has a special case for this pattern. ClickHouse probably does too. See
SUM(..)clauses #15524Thus I reluctantly conclude that we should have one too.
What changes are included in this PR?
This is an alternate to my first attempt.
SUM(expr + scalar)-->SUM(expr) + scalar*COUNT(expr)#20665In particular, since this is such a ClickBench specific rule, I wanted to
Minimize the downstream API / upgrade impact (aka not change existing APIs)
Optimize performance for the case where this rewrite will not apply (most times)
Add a rewrite
SUM(expr + scalar)-->SUM(expr) + scalar*COUNT(expr)Tests for same
Note there are quite a few other ideas to potentially make this more general on #15524 but I am going with the simple thing of making it work for the usecase we have in hand (ClickBench)
Are these changes tested?
Yes, new tests are added
Are there any user-facing changes?
Faster performance
🚀