Add MultiDistinctToCrossJoin optimizer rule for parallel distinct aggregates#20940
Open
Dandandan wants to merge 10 commits intoapache:mainfrom
Open
Add MultiDistinctToCrossJoin optimizer rule for parallel distinct aggregates#20940Dandandan wants to merge 10 commits intoapache:mainfrom
Dandandan wants to merge 10 commits intoapache:mainfrom
Conversation
…ggregates Rewrites queries with multiple DISTINCT aggregates on different columns (e.g. SELECT COUNT(DISTINCT a), COUNT(DISTINCT b) FROM t) into a UNION ALL of individual aggregates with an outer MAX to combine results. This enables parallel execution of each distinct aggregate via InterleaveExec, and each branch also benefits from SingleDistinctToGroupBy optimization. Also adds function_registry support to OptimizerContext and removes the redundant clickbench_extended.slt (already covered by clickbench.slt). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
Author
|
run benchmark clickbench_extended |
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… method Use the existing OptimizerConfig::function_registry() trait method (which SessionState provides in production) instead of adding registry support to OptimizerContext. Tests use a simple TestConfig wrapper. Also remove redundant tests and clean up imports. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
🤖 Benchmark completed (GKE) | trigger Details
Resource Usageclickbench_extended — base (merge-base)
clickbench_extended — branch
|
CrossJoinExec runs each branch sequentially, so only one hash table is live at a time. This is better for memory locality on high-cardinality distinct aggregates vs UNION ALL which runs branches concurrently. Also removes the function registry dependency (no MAX aggregate needed), simplifying the implementation significantly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
Author
|
run benchmark clickbench_extended |
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Replace double-match (ref guard + unreachable move) with single destructure-by-move and early return via try_new_with_schema - Use into_iter() instead of iter() to move Exprs into sub-aggregates instead of cloning them Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Use assert_optimized_plan_eq_display_indent_snapshot directly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
🤖 Benchmark completed (GKE) | trigger Details
Resource Usageclickbench_extended — base (merge-base)
clickbench_extended — branch
|
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.
Which issue does this PR close?
Rationale for this change
Speedup / use less memory for multiple
COUNT(distinct)s.What changes are included in this PR?
Add the
MultiDistinctToCrossJoinwith some tests, update plans.Are these changes tested?
New and existing.
Are there any user-facing changes?
Note: I used Claude to generate the code, I reviewed the code myself.