Skip to content

fix(plan): preserve ROLLUP source order keys - #26357

Merged
XuPeng-SH merged 7 commits into
matrixorigin:mainfrom
ck89119:issue-26269-main
Jul 29, 2026
Merged

XuPeng-SH merged 7 commits into
matrixorigin:mainfrom
ck89119:issue-26269-main

Conversation

@ck89119

@ck89119 ck89119 commented Jul 29, 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 #26269

What this PR does / why we need it:

ROLLUP, CUBE, and GROUPING SETS are expanded into an internal UNION ALL. ORDER BY expressions containing GROUPING() were already materialized as hidden branch projections, but ordinary source grouping columns were left to bind above the union. When the visible select list wrapped those columns for display, the original source columns were no longer available and planning failed with column ... does not exist.

This change:

  • materializes source-dependent non-DISTINCT grouping-set order keys while branch bindings are still available;
  • reuses visible projections when an ORDER BY expression matches a selected expression, including after star expansion, so expressions are not evaluated twice;
  • preserves ORDER BY alias precedence, DISTINCT restrictions, positional ordering, and the final output schema;
  • adds planner coverage for ROLLUP, CUBE, GROUPING SETS, aliases, visible-expression reuse, hidden source keys, and DISTINCT, plus a distributed ROLLUP regression case with source NULL values.

Validation:

  • .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=20m ./pkg/sql/plan
  • .agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=20m ./pkg/sql/plan
  • go build -mod=readonly ./pkg/sql/plan/...
  • go vet -mod=readonly ./pkg/sql/plan/...
  • make static-check
  • rollup BVT: 162 passed, 0 failed, 2 ignored
  • git diff --check

@mergify mergify Bot added the queued label Jul 29, 2026
@mergify

mergify Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-07-29 14:09 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-07-29 14:20 UTC · at 9eabea01dd1c625d0a6a6b98d23b9ef67175c443

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

Waiting for
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
All conditions
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]

Reason

Pull request #26357 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.

Failing checks:

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 ce6ce78 into matrixorigin:main Jul 29, 2026
23 of 25 checks passed
@mergify mergify Bot added dequeued and removed queued labels Jul 29, 2026
@ck89119
ck89119 deleted the issue-26269-main branch July 29, 2026 14:22
mergify Bot pushed a commit that referenced this pull request Jul 30, 2026
…6418)

This reverts squash commit `538a45b37d7162182734c943c59bbbd723da3508` from #26331 at the author request.

The revert removes the multi-reference CTE reuse planner, query-scoped materialized source and spill path, and the associated compile/Dispatch/Merge wiring as one complete unit. Multi-reference CTEs return to independent inline planning, and sink scans use the existing streaming pipeline path.

The revert is synchronized with current `upstream/main` (`2c9608dd45960126ff3a91fc3bbb0addd53d816d`). Later overlapping fixes #26357 and #26393 remain present.

There is no SQL syntax, protobuf, public API, or persistence-format change.

### Validation

Exact head `fb1b16f27b9665203197678f385815755b143b06`:

- previous head `d693b810af44d4d9f0ae22ad3b18d68e78e6dc06`: all major functional CI jobs passed; Matrixone Utils Coverage alone failed because modified-line coverage was exactly 75%, while the gate requires strictly greater than 75%
- added `TestDispatchResetSkipsInvalidRemoteReceiversAndNotifiesHealthyPeer`, covering both nil receiver and nil error-channel guards while proving that a later healthy receiver still receives the original terminal error
- focused coverprofile: `pkg/sql/colexec/dispatch/types.go:227.33,234.14` changed from count 0 in CI to count 1 locally
- exact-head remote Coverage: PASS with 4/4 modified lines covered (`pr_coverage=1.0`, threshold `>0.75`)
- affected planner/compile/dispatch/merge package tests: PASS
- complete affected owning packages under `-race -count=1`: PASS
- focused dispatch terminal and compile sink-scan tests under `-race -count=20`: PASS
- affected package build and vet: PASS
- `git diff --check`: PASS
- exact reverse/overlap audit: only later #26357 and #26393 edits remain relative to the #26331 parent
- schema-v4 preflight: `PASS review=PASS validation=PASS`

BVT: the previous exact-head Proxy multi-CN and pessimistic BVT jobs passed. This follow-up adds package-internal unit coverage only and does not change product behavior.

### QA decision

QA required: yes. This rolls back optimizer selection and the materialized fan-out execution path. CI and environment-level analytical-query regression coverage should complete before merge.

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## 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#26269

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

ROLLUP, CUBE, and GROUPING SETS are expanded into an internal UNION ALL.
ORDER BY expressions containing GROUPING() were already materialized as
hidden branch projections, but ordinary source grouping columns were
left to bind above the union. When the visible select list wrapped those
columns for display, the original source columns were no longer
available and planning failed with `column ... does not exist`.

This change:

- materializes source-dependent non-DISTINCT grouping-set order keys
while branch bindings are still available;
- reuses visible projections when an ORDER BY expression matches a
selected expression, including after star expansion, so expressions are
not evaluated twice;
- preserves ORDER BY alias precedence, DISTINCT restrictions, positional
ordering, and the final output schema;
- adds planner coverage for ROLLUP, CUBE, GROUPING SETS, aliases,
visible-expression reuse, hidden source keys, and DISTINCT, plus a
distributed ROLLUP regression case with source NULL values.

Validation:

- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=20m
./pkg/sql/plan`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=20m
./pkg/sql/plan`
- `go build -mod=readonly ./pkg/sql/plan/...`
- `go vet -mod=readonly ./pkg/sql/plan/...`
- `make static-check`
- rollup BVT: 162 passed, 0 failed, 2 ignored
- `git diff --check`

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 added a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…#26331)" (matrixorigin#26418)

This reverts squash commit `538a45b37d7162182734c943c59bbbd723da3508` from matrixorigin#26331 at the author request.

The revert removes the multi-reference CTE reuse planner, query-scoped materialized source and spill path, and the associated compile/Dispatch/Merge wiring as one complete unit. Multi-reference CTEs return to independent inline planning, and sink scans use the existing streaming pipeline path.

The revert is synchronized with current `upstream/main` (`2c9608dd45960126ff3a91fc3bbb0addd53d816d`). Later overlapping fixes matrixorigin#26357 and matrixorigin#26393 remain present.

There is no SQL syntax, protobuf, public API, or persistence-format change.

### Validation

Exact head `fb1b16f27b9665203197678f385815755b143b06`:

- previous head `d693b810af44d4d9f0ae22ad3b18d68e78e6dc06`: all major functional CI jobs passed; Matrixone Utils Coverage alone failed because modified-line coverage was exactly 75%, while the gate requires strictly greater than 75%
- added `TestDispatchResetSkipsInvalidRemoteReceiversAndNotifiesHealthyPeer`, covering both nil receiver and nil error-channel guards while proving that a later healthy receiver still receives the original terminal error
- focused coverprofile: `pkg/sql/colexec/dispatch/types.go:227.33,234.14` changed from count 0 in CI to count 1 locally
- exact-head remote Coverage: PASS with 4/4 modified lines covered (`pr_coverage=1.0`, threshold `>0.75`)
- affected planner/compile/dispatch/merge package tests: PASS
- complete affected owning packages under `-race -count=1`: PASS
- focused dispatch terminal and compile sink-scan tests under `-race -count=20`: PASS
- affected package build and vet: PASS
- `git diff --check`: PASS
- exact reverse/overlap audit: only later matrixorigin#26357 and matrixorigin#26393 edits remain relative to the matrixorigin#26331 parent
- schema-v4 preflight: `PASS review=PASS validation=PASS`

BVT: the previous exact-head Proxy multi-CN and pessimistic BVT jobs passed. This follow-up adds package-internal unit coverage only and does not change product behavior.

### QA decision

QA required: yes. This rolls back optimizer selection and the materialized fan-out execution path. CI and environment-level analytical-query regression coverage should complete before merge.

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## 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#26269

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

ROLLUP, CUBE, and GROUPING SETS are expanded into an internal UNION ALL.
ORDER BY expressions containing GROUPING() were already materialized as
hidden branch projections, but ordinary source grouping columns were
left to bind above the union. When the visible select list wrapped those
columns for display, the original source columns were no longer
available and planning failed with `column ... does not exist`.

This change:

- materializes source-dependent non-DISTINCT grouping-set order keys
while branch bindings are still available;
- reuses visible projections when an ORDER BY expression matches a
selected expression, including after star expansion, so expressions are
not evaluated twice;
- preserves ORDER BY alias precedence, DISTINCT restrictions, positional
ordering, and the final output schema;
- adds planner coverage for ROLLUP, CUBE, GROUPING SETS, aliases,
visible-expression reuse, hidden source keys, and DISTINCT, plus a
distributed ROLLUP regression case with source NULL values.

Validation:

- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=20m
./pkg/sql/plan`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=20m
./pkg/sql/plan`
- `go build -mod=readonly ./pkg/sql/plan/...`
- `go vet -mod=readonly ./pkg/sql/plan/...`
- `make static-check`
- rollup BVT: 162 passed, 0 failed, 2 ignored
- `git diff --check`

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 added a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…#26331)" (matrixorigin#26418)

This reverts squash commit `538a45b37d7162182734c943c59bbbd723da3508` from matrixorigin#26331 at the author request.

The revert removes the multi-reference CTE reuse planner, query-scoped materialized source and spill path, and the associated compile/Dispatch/Merge wiring as one complete unit. Multi-reference CTEs return to independent inline planning, and sink scans use the existing streaming pipeline path.

The revert is synchronized with current `upstream/main` (`2c9608dd45960126ff3a91fc3bbb0addd53d816d`). Later overlapping fixes matrixorigin#26357 and matrixorigin#26393 remain present.

There is no SQL syntax, protobuf, public API, or persistence-format change.

### Validation

Exact head `fb1b16f27b9665203197678f385815755b143b06`:

- previous head `d693b810af44d4d9f0ae22ad3b18d68e78e6dc06`: all major functional CI jobs passed; Matrixone Utils Coverage alone failed because modified-line coverage was exactly 75%, while the gate requires strictly greater than 75%
- added `TestDispatchResetSkipsInvalidRemoteReceiversAndNotifiesHealthyPeer`, covering both nil receiver and nil error-channel guards while proving that a later healthy receiver still receives the original terminal error
- focused coverprofile: `pkg/sql/colexec/dispatch/types.go:227.33,234.14` changed from count 0 in CI to count 1 locally
- exact-head remote Coverage: PASS with 4/4 modified lines covered (`pr_coverage=1.0`, threshold `>0.75`)
- affected planner/compile/dispatch/merge package tests: PASS
- complete affected owning packages under `-race -count=1`: PASS
- focused dispatch terminal and compile sink-scan tests under `-race -count=20`: PASS
- affected package build and vet: PASS
- `git diff --check`: PASS
- exact reverse/overlap audit: only later matrixorigin#26357 and matrixorigin#26393 edits remain relative to the matrixorigin#26331 parent
- schema-v4 preflight: `PASS review=PASS validation=PASS`

BVT: the previous exact-head Proxy multi-CN and pessimistic BVT jobs passed. This follow-up adds package-internal unit coverage only and does not change product behavior.

### QA decision

QA required: yes. This rolls back optimizer selection and the materialized fan-out execution path. CI and environment-level analytical-query regression coverage should complete before merge.

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## 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#26269

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

ROLLUP, CUBE, and GROUPING SETS are expanded into an internal UNION ALL.
ORDER BY expressions containing GROUPING() were already materialized as
hidden branch projections, but ordinary source grouping columns were
left to bind above the union. When the visible select list wrapped those
columns for display, the original source columns were no longer
available and planning failed with `column ... does not exist`.

This change:

- materializes source-dependent non-DISTINCT grouping-set order keys
while branch bindings are still available;
- reuses visible projections when an ORDER BY expression matches a
selected expression, including after star expansion, so expressions are
not evaluated twice;
- preserves ORDER BY alias precedence, DISTINCT restrictions, positional
ordering, and the final output schema;
- adds planner coverage for ROLLUP, CUBE, GROUPING SETS, aliases,
visible-expression reuse, hidden source keys, and DISTINCT, plus a
distributed ROLLUP regression case with source NULL values.

Validation:

- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=20m
./pkg/sql/plan`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=20m
./pkg/sql/plan`
- `go build -mod=readonly ./pkg/sql/plan/...`
- `go vet -mod=readonly ./pkg/sql/plan/...`
- `make static-check`
- rollup BVT: 162 passed, 0 failed, 2 ignored
- `git diff --check`

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 added a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…#26331)" (matrixorigin#26418)

This reverts squash commit `538a45b37d7162182734c943c59bbbd723da3508` from matrixorigin#26331 at the author request.

The revert removes the multi-reference CTE reuse planner, query-scoped materialized source and spill path, and the associated compile/Dispatch/Merge wiring as one complete unit. Multi-reference CTEs return to independent inline planning, and sink scans use the existing streaming pipeline path.

The revert is synchronized with current `upstream/main` (`2c9608dd45960126ff3a91fc3bbb0addd53d816d`). Later overlapping fixes matrixorigin#26357 and matrixorigin#26393 remain present.

There is no SQL syntax, protobuf, public API, or persistence-format change.

### Validation

Exact head `fb1b16f27b9665203197678f385815755b143b06`:

- previous head `d693b810af44d4d9f0ae22ad3b18d68e78e6dc06`: all major functional CI jobs passed; Matrixone Utils Coverage alone failed because modified-line coverage was exactly 75%, while the gate requires strictly greater than 75%
- added `TestDispatchResetSkipsInvalidRemoteReceiversAndNotifiesHealthyPeer`, covering both nil receiver and nil error-channel guards while proving that a later healthy receiver still receives the original terminal error
- focused coverprofile: `pkg/sql/colexec/dispatch/types.go:227.33,234.14` changed from count 0 in CI to count 1 locally
- exact-head remote Coverage: PASS with 4/4 modified lines covered (`pr_coverage=1.0`, threshold `>0.75`)
- affected planner/compile/dispatch/merge package tests: PASS
- complete affected owning packages under `-race -count=1`: PASS
- focused dispatch terminal and compile sink-scan tests under `-race -count=20`: PASS
- affected package build and vet: PASS
- `git diff --check`: PASS
- exact reverse/overlap audit: only later matrixorigin#26357 and matrixorigin#26393 edits remain relative to the matrixorigin#26331 parent
- schema-v4 preflight: `PASS review=PASS validation=PASS`

BVT: the previous exact-head Proxy multi-CN and pessimistic BVT jobs passed. This follow-up adds package-internal unit coverage only and does not change product behavior.

### QA decision

QA required: yes. This rolls back optimizer selection and the materialized fan-out execution path. CI and environment-level analytical-query regression coverage should complete before merge.

Approved by: @XuPeng-SH

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/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] ROLLUP ORDER BY GROUPING fails with wrapped selected grouping keys

3 participants