Skip to content

fix(colexec): report materialized CTE spill stats - #27110

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
aunjgr:fix/27107-materialized-cte-spill-stats
Aug 13, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
aunjgr:fix/27107-materialized-cte-spill-stats

Conversation

@aunjgr

@aunjgr aunjgr commented Aug 13, 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:

issue #27107

What this PR does / why we need it:

Materialized CTE spill is owned by the shared source, but the producer dispatch previously reported only the source's retained memory. As a result, runtime spill reservations were real while EXPLAIN ANALYZE showed no spill on any operator.

This change returns the exact storage effect of each source append and attributes successful spill-byte and spill-row deltas to the materialized producer's operator analyzer. A spill is reported only after the complete framed record is written, and it is counted once at the producer rather than once per reader.

Regression coverage verifies zero spill for retained batches, exact framed-record accounting for source spill, producer analyzer attribution, source reuse, and race safety.

Validation:

  • go build -mod=readonly ./pkg/sql/internal/materialized ./pkg/sql/colexec/dispatch
  • go vet -mod=readonly ./pkg/sql/internal/materialized ./pkg/sql/colexec/dispatch
  • full tests for ./pkg/sql/internal/materialized and ./pkg/sql/colexec/dispatch
  • focused Test_explainResourceOverview in ./pkg/sql/compile
  • full owning-package race tests and 100 race-stressed iterations of the new source/dispatch paths

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

Deep review completed against main@76f62df1 (merge-base 76f62df), head 1fb3be0.

No blocking findings. The per-append stats remain under the source ownership/locking boundary, report spill only after the full framed record is written, preserve the existing Append API, and attribute deltas exactly once to the materialized producer analyzer. I traced producer -> shared source -> spill/read -> Reset/reader release -> reuse and the physical-plan aggregation path; no new leak, wait-for, unbounded-growth, generation, compatibility, or material hot-path-cost issue was found.

Validation on the reviewed head: changed-package build/vet/full tests; focused materialized source/dispatch/merge/compile tests; existing public SQL two-consumer CTE integration regression; focused race stress at N=100 for all new/modified tests; and full owning-package race runs.

@XuPeng-SH
XuPeng-SH merged commit 223b659 into matrixorigin:main Aug 13, 2026
21 of 23 checks passed
@aunjgr
aunjgr deleted the fix/27107-materialized-cte-spill-stats branch August 14, 2026 03:11
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
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#27107

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

Materialized CTE spill is owned by the shared source, but the producer
dispatch previously reported only the source's retained memory. As a
result, runtime spill reservations were real while `EXPLAIN ANALYZE`
showed no spill on any operator.

This change returns the exact storage effect of each source append and
attributes successful spill-byte and spill-row deltas to the
materialized producer's operator analyzer. A spill is reported only
after the complete framed record is written, and it is counted once at
the producer rather than once per reader.

Regression coverage verifies zero spill for retained batches, exact
framed-record accounting for source spill, producer analyzer
attribution, source reuse, and race safety.

Validation:

- `go build -mod=readonly ./pkg/sql/internal/materialized
./pkg/sql/colexec/dispatch`
- `go vet -mod=readonly ./pkg/sql/internal/materialized
./pkg/sql/colexec/dispatch`
- full tests for `./pkg/sql/internal/materialized` and
`./pkg/sql/colexec/dispatch`
- focused `Test_explainResourceOverview` in `./pkg/sql/compile`
- full owning-package race tests and 100 race-stressed iterations of the
new source/dispatch paths

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
## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue matrixorigin#27107

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

Materialized CTE spill is owned by the shared source, but the producer
dispatch previously reported only the source's retained memory. As a
result, runtime spill reservations were real while `EXPLAIN ANALYZE`
showed no spill on any operator.

This change returns the exact storage effect of each source append and
attributes successful spill-byte and spill-row deltas to the
materialized producer's operator analyzer. A spill is reported only
after the complete framed record is written, and it is counted once at
the producer rather than once per reader.

Regression coverage verifies zero spill for retained batches, exact
framed-record accounting for source spill, producer analyzer
attribution, source reuse, and race safety.

Validation:

- `go build -mod=readonly ./pkg/sql/internal/materialized
./pkg/sql/colexec/dispatch`
- `go vet -mod=readonly ./pkg/sql/internal/materialized
./pkg/sql/colexec/dispatch`
- full tests for `./pkg/sql/internal/materialized` and
`./pkg/sql/colexec/dispatch`
- focused `Test_explainResourceOverview` in `./pkg/sql/compile`
- full owning-package race tests and 100 race-stressed iterations of the
new source/dispatch paths

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
## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue matrixorigin#27107

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

Materialized CTE spill is owned by the shared source, but the producer
dispatch previously reported only the source's retained memory. As a
result, runtime spill reservations were real while `EXPLAIN ANALYZE`
showed no spill on any operator.

This change returns the exact storage effect of each source append and
attributes successful spill-byte and spill-row deltas to the
materialized producer's operator analyzer. A spill is reported only
after the complete framed record is written, and it is counted once at
the producer rather than once per reader.

Regression coverage verifies zero spill for retained batches, exact
framed-record accounting for source spill, producer analyzer
attribution, source reuse, and race safety.

Validation:

- `go build -mod=readonly ./pkg/sql/internal/materialized
./pkg/sql/colexec/dispatch`
- `go vet -mod=readonly ./pkg/sql/internal/materialized
./pkg/sql/colexec/dispatch`
- full tests for `./pkg/sql/internal/materialized` and
`./pkg/sql/colexec/dispatch`
- focused `Test_explainResourceOverview` in `./pkg/sql/compile`
- full owning-package race tests and 100 race-stressed iterations of the
new source/dispatch paths

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants