Skip to content

Optimize Clickbench Query 29 by adding a new Optimizer rule#20180

Open
devanshu0987 wants to merge 10 commits intoapache:mainfrom
devanshu0987:query_29
Open

Optimize Clickbench Query 29 by adding a new Optimizer rule#20180
devanshu0987 wants to merge 10 commits intoapache:mainfrom
devanshu0987:query_29

Conversation

@devanshu0987
Copy link
Contributor

@devanshu0987 devanshu0987 commented Feb 6, 2026

Which issue does this PR close?

  • Closes #.

Rationale for this change

  • ClickBench Query 29 executes 90 separate SUM operations:
    • SUM(ResolutionWidth), SUM(ResolutionWidth + 1), SUM(ResolutionWidth + 2), ..., SUM(ResolutionWidth + 89)
  • https://www.redpanda.com/blog/oxla-our-road-to-improving-oxla-results-on-clickbench#what-we-had-to-optimize
    • This blog post from Redpand mentioned an optimization they did to optimize this query.
  • Transform aggregations SUM(A + k) into SUM(A) + k * COUNT(*)
  • This will transform 90 SUM aggregations into 1 SUM and 1 COUNT aggregation and the results will be reused for all projections.
    • It is added before CommonSubexprEliminate to allow re use of the common SUM and COUNT expression.

What changes are included in this PR?

  • New optimizer rule RewriteAggregateWithConstant

Are these changes tested?

  • Unit Tests
  • SLT Tests
  • Explain over Query 29 shows the reuse
    • I would like the core-contributors to run the benchmark to prove the impact.

Are there any user-facing changes?

No

AI Usage

  • Yes. I have heavily used assistance from various models.
  • Although, I have gone through multiple rounds of clean up to reduce unintended/unnecessary changes.

@github-actions github-actions bot added optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt) labels Feb 6, 2026
@devanshu0987 devanshu0987 marked this pull request as draft February 6, 2026 04:11
@devanshu0987 devanshu0987 marked this pull request as ready for review February 6, 2026 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant