Skip to content

fix(plan): restore empty correlated DISTINCT aggregate results - #28642

Merged
XuPeng-SH merged 8 commits into
matrixorigin:mainfrom
aunjgr:fix/correlated-distinct-empty-result-28300
Sep 11, 2026
Merged

XuPeng-SH merged 8 commits into
matrixorigin:mainfrom
aunjgr:fix/correlated-distinct-empty-result-28300

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:

Fixes #28300

What this PR does / why we need it:

fix(plan): restore empty correlated DISTINCT aggregate results

@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 exact head 3ca767e against main db4edb4. No concrete blocker found.

The fix clears only the DISTINCT flag before consulting the aggregate executor's canonical empty-input contract. It does not remove DISTINCT from the aggregate plan or change its arguments/state. Thus a missing equality-correlated group restores COUNT(DISTINCT) to typed zero, while SUM/AVG/GROUP_CONCAT remain NULL; a matching all-NULL group retains the same outcomes, and populated groups retain their computed distinct result. The mask is identical to the existing aggregate-ID convention and leaves ordinary aggregate IDs unchanged.

I traced both direct AGG and PROJECT->AGG callers, post-LEFT-JOIN expression restoration, copied projection expressions, correlation-key ownership and existing eligibility guards. Explicit grouping, HAVING/row-removing wrappers, LIMIT and unsupported shapes are not newly pulled through this helper. No join predicate, dedup implementation, partial/final state format, prepared parameter ownership or persisted metadata changes. The added work is one planner-time bitmask; no new per-row allocation or resource lifetime.

The typed tests prove COUNT gets its zero-producing CASE while NULL-on-empty aggregates retain the projected expression, and plan tests prove the supported correlated DISTINCT forms become reachable without correlated expressions. The public SQL oracle uses duplicate non-NULL values, a matching all-NULL group and a completely missing group, with independently specified null-safe expected results and deterministic concatenation order. These distinguish the target failure rather than merely accepting generated output.

Validation/limits: complete four-file diff, issue #28300, PR comments/history and exact-head planner/empty-result consumers inspected; head/base rechecked before posting. I did not independently run UT/BVT, mixed-version/distributed SQL or performance tests, and did not wait for CI. Broader decorrelation coverage is useful existing/follow-up evidence, not a blocker for this localized ID-classification correction.

@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 10:16 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-09-11 10:20 UTC · at e9d95aa99858367718cded54b49c24f7310542e6

This pull request spent 3 minutes 44 seconds in the queue, with no time running CI.

Reason

The pull request can't be updated

This pull request seems to come 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, or update the branch manually.

Hint

You should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue, 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 5c79a2b into matrixorigin:main Sep 11, 2026
22 of 23 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
…xorigin#28642)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#28300

## What this PR does / why we need it:

fix(plan): restore empty correlated DISTINCT aggregate results

---------

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
…xorigin#28642)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#28300

## What this PR does / why we need it:

fix(plan): restore empty correlated DISTINCT aggregate results

---------

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
…xorigin#28642)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#28300

## What this PR does / why we need it:

fix(plan): restore empty correlated DISTINCT aggregate results

---------

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/bug Something isn't working size/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Compatibility]: DISTINCT aggregates are rejected in correlated scalar subqueries

3 participants