Repository navigation
perf(plan): rewrite standalone AVG(DISTINCT) through grouped deduplication - #28644
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
…to perf/avg-distinct-rewrite-9049
XuPeng-SH
left a comment
There was a problem hiding this comment.
Reviewed 95ad2d3 against main cd8e8d9. No concrete merge-blocking issue found.
This extends the existing COUNT/SUM DISTINCT logical rewrite to AVG: deduplicate the pair (original grouping keys, bound AVG argument), then apply the same AVG overload to the deduplicated argument. “Standalone” means one aggregate in that AGG node, not absence of GROUP BY. The inner grouping retains NULL-valued candidates; outer AVG ignores them, preserves all-NULL groups, and its zero-count finalization remains NULL for scalar empty input. Existing grouping-key/PAD SPACE handling and argument type metadata are reused; this is not AVG-of-partial-averages or a newly typed SUM/COUNT expression.
The original grouping output tags and outer aggregate/result expression remain in place. Filters/joins remain below the inserted dedup node, while outer result consumers retain their references. Mixed aggregates and nontrivial grouping sets keep the conservative DISTINCT fallback; window nodes are not rewritten. AVG does not opt into the COUNT-only distinct-key local-preaggregation/shuffle heuristic. After dedup, ordinary AVG uses its existing sum/count partial-state merge and decimal/integer accumulator choices rather than a new wire layout. Signed-zero handling is present in the existing DISTINCT argument codec as well as grouping key normalization. As with ordinary floating aggregation, this is not a promise of bitwise stability under changed accumulation order.
Performance tradeoff: an extra ordinary grouping stage can distribute/spill distinct-key work, but high NDV/skew can add grouping/shuffle overhead. No speedup is inferred without measurements. No shared mutable execution state or new serialization fields are introduced.
The added tests verify the AVG plan shape, preserved AVG ID, cleared DISTINCT flag, conservative mixed/grouping-set fallbacks, and SQL-level physical-group-key annotation. Optional follow-up: execution-level before/after controls for empty/all-NULL/grouped data, decimal extremes and distributed input would strengthen the oracle, plus high/low-NDV measurements; this is not a blocker solely for missing supplementary evidence.
Validation limits: current four-file diff, live discussion, full rewrite/eligibility code, relevant exact-head aggregate dispatch/fill/merge/zero-count logic and DISTINCT key normalization inspected. No new native UT, BVT, distributed SQL or benchmark execution; no CI wait. Head/base rechecked before posting.
|
Queued — the merge queue status continues in this comment ↓. |
Merge Queue Status
This pull request spent 56 seconds in the queue, with no time running CI. Waiting for any of
All conditions
ReasonPull request #28644 has been dequeued Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.
HintYou should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it. Tick the box to put this pull request back in the merge queue (same as
|
…ation (matrixorigin#28644) ## What type of PR is this? - [ ] API-change - [ ] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Refs matrixorigin#9049 ## What this PR does / why we need it: perf(plan): rewrite standalone AVG(DISTINCT) through grouped deduplication Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…ation (matrixorigin#28644) ## What type of PR is this? - [ ] API-change - [ ] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Refs matrixorigin#9049 ## What this PR does / why we need it: perf(plan): rewrite standalone AVG(DISTINCT) through grouped deduplication Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…ation (matrixorigin#28644) ## What type of PR is this? - [ ] API-change - [ ] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Refs matrixorigin#9049 ## What this PR does / why we need it: perf(plan): rewrite standalone AVG(DISTINCT) through grouped deduplication Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
What type of PR is this?
Which issue(s) this PR fixes:
Refs #9049
What this PR does / why we need it:
perf(plan): rewrite standalone AVG(DISTINCT) through grouped deduplication