perf(optimizer): avoid redundant aggregate planning work - #24977
perf(optimizer): avoid redundant aggregate planning work#24977neilconway wants to merge 2 commits into
Conversation
Reduce work in EliminateDuplicatedExpr with two independent optimizations: 1. Before deduplication, return immediately for zero or one grouping expression. These lists cannot contain duplicate entries, so avoid constructing the deduplication set as well. 2. After deduplication, reuse the Aggregate if no grouping expressions were removed. This avoids repeating validation, schema construction, and functional-dependency derivation. This improves query optimizer performance on the TPC-H and TPC-DS queries by about 5%.
|
run benchmark sql_planner |
|
🤖 Benchmark running (GKE) | trigger CPU Details (lscpu)Comparing neilc/perf-planner-agg-unchanged (675cc46) to 722cbf2 (merge-base) diff Run configurationrun benchmark sql_plannerResults will be posted here when complete File an issue against this benchmark runner |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #24977 +/- ##
==========================================
- Coverage 81.67% 81.67% -0.01%
==========================================
Files 1126 1126
Lines 414533 414591 +58
Branches 414533 414591 +58
==========================================
+ Hits 338562 338602 +40
- Misses 56058 56063 +5
- Partials 19913 19926 +13 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ryux1
left a comment
There was a problem hiding this comment.
Checked both fast paths and the existing duplicate-removal path. For zero or one grouping expression the aggregate is returned directly; for a larger duplicate-free list, IndexSet preserves first-occurrence order and moves the same Expr values back while retaining the existing schema and functional dependencies. When duplicates are present, Aggregate::try_new is still used so validation and derived schema state are recomputed. The added tests exercise schema identity and ordered deduplication, and the reported CI matrix is green.
|
🤖 Benchmark completed (GKE) | trigger Instance: Comparing neilc/perf-planner-agg-unchanged (675cc46) to 722cbf2 (merge-base) diff Run configurationrun benchmark sql_plannerCPU Details (lscpu)Details
Resource Usagesql_planner — base (merge-base)
sql_planner — branch
File an issue against this benchmark runner |
Which issue does this PR close?
Rationale for this change
Reduce redundant work in
EliminateDuplicatedExprwith two independent optimizations:Before deduplication, return immediately for zero or one grouping expression. These lists cannot contain duplicate entries, so avoid constructing the deduplication set as well.
After deduplication, reuse the Aggregate if no grouping expressions were removed. This avoids repeating validation, schema construction, and functional-dependency derivation.
This improves query optimizer performance on the TPC-H and TPC-DS queries by about 5%.
What changes are included in this PR?
What is the testing strategy for this PR?
Existing tests pass. New unit tests added to (1) confirm existing behavior (duplicate removal) (2) confirm optimization (schema reused when no duplicate removal work needs to be done).
I checked that the tests in category (2) fail if the optimization is disabled.
Are there any user-facing changes?
No.