Skip to content

perf(plan): rewrite standalone AVG(DISTINCT) through grouped deduplication - #28644

Merged
XuPeng-SH merged 7 commits into
matrixorigin:mainfrom
aunjgr:perf/avg-distinct-rewrite-9049
Sep 11, 2026
Merged

XuPeng-SH merged 7 commits into
matrixorigin:mainfrom
aunjgr:perf/avg-distinct-rewrite-9049

Conversation

@aunjgr

@aunjgr aunjgr commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

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

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mergify

mergify Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Queued — the merge queue status continues in this comment ↓.

@mergify mergify Bot added the queued label Sep 11, 2026
@mergify

mergify Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-11 06:06 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-09-11 06:07 UTC · at b5bba7307c8a7d04becf5ca3a050773d4cdded28

This pull request spent 56 seconds in the queue, with no time running CI.

Waiting for any of
  • check-neutral = CI Required
  • check-skipped = CI Required
  • check-success = CI Required
All conditions

Reason

Pull 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.

The author needs to enable "Allow edits from maintainers" on this pull request.

Hint

You 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.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

@XuPeng-SH
XuPeng-SH merged commit 7013fbb into matrixorigin:main Sep 11, 2026
5 of 6 checks passed
@mergify mergify Bot added dequeued and removed queued labels Sep 11, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…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>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…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>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…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>

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement size/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants