Skip to content

fix(compile): close materialized sources per attempt - #28269

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/fix-28266-materialized-lifecycle
Sep 5, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/fix-28266-materialized-lifecycle

Conversation

@XuPeng-SH

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 #28266

What this PR does / why we need it:

A prepared information_schema.COLUMNS lookup with LIMIT can stop lazy UNION ALL before all statically planned readers of the shared mo_current_roles CTE start. Operator Reset therefore cannot release those unstarted readers, and the next prepared execution rejects the still-active materialized source generation.

This change makes one pipeline execution attempt the final owner of every materialized generation it successfully opens. Operator cleanup remains the eager path; an attempt-level deferred cleanup closes skipped readers on success, initialization or execution errors, and panics. Partial initialization returns only sources opened by that attempt, so an active source owned elsewhere is never closed accidentally.

The reuse error now reports the generation and unreleased owner IDs. Normal already-released generations use a fast no-op Close, and planner materialization plus lazy UNION behavior remain unchanged.

Validation

  • make build
  • full normal tests for ./pkg/sql/internal/materialized and ./pkg/sql/compile
  • full race tests for both owning packages
  • go vet for both owning packages
  • repeated focused race tests for success, execution-error, panic, cancellation, and prepared-reuse lifecycle cases
  • fresh quickstart black-box execution of the exact parameterized information_schema.COLUMNS LIMIT query across hit, miss, repeated execution, and schema recreation
  • EXPLAIN confirms mo_current_roles materialization, UNION ALL, LIMIT, and Sink Scan reuse remain enabled
  • distributed metadata regression executes the prepared query twice on one connection

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

Choose a reason for hiding this comment

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

Deep review of commit e2bddfb.

No blocking issues found. The attempt-level ownership model correctly closes every materialized source generation opened by the attempt, including statically planned but unstarted lazy readers, initialization/ execution errors, panic unwinding, cancellation, and prepared-plan retry reuse. Scope completion barriers are in place before Close, and Source.Close is idempotent for already-released generations.

Validation: local materialized UT, compile UT, focused race repetitions, full pkg/sql/compile UT; GitHub UT, SCA, coverage, Compose BVT, and multi-CN BVT all passed.

Non-blocking note: the diagnostic does not include statement/trace or materialized-step ID; this can be improved separately.

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:

issue matrixorigin#28266

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

A prepared information_schema.COLUMNS lookup with LIMIT can stop lazy
UNION ALL before all statically planned readers of the shared
mo_current_roles CTE start. Operator Reset therefore cannot release
those unstarted readers, and the next prepared execution rejects the
still-active materialized source generation.

This change makes one pipeline execution attempt the final owner of
every materialized generation it successfully opens. Operator cleanup
remains the eager path; an attempt-level deferred cleanup closes skipped
readers on success, initialization or execution errors, and panics.
Partial initialization returns only sources opened by that attempt, so
an active source owned elsewhere is never closed accidentally.

The reuse error now reports the generation and unreleased owner IDs.
Normal already-released generations use a fast no-op Close, and planner
materialization plus lazy UNION behavior remain unchanged.

## Validation

- make build
- full normal tests for ./pkg/sql/internal/materialized and
./pkg/sql/compile
- full race tests for both owning packages
- go vet for both owning packages
- repeated focused race tests for success, execution-error, panic,
cancellation, and prepared-reuse lifecycle cases
- fresh quickstart black-box execution of the exact parameterized
information_schema.COLUMNS LIMIT query across hit, miss, repeated
execution, and schema recreation
- EXPLAIN confirms mo_current_roles materialization, UNION ALL, LIMIT,
and Sink Scan reuse remain enabled
- distributed metadata regression executes the prepared query twice on
one connection

Signed-off-by: XuPeng-SH <[email protected]>
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:

issue matrixorigin#28266

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

A prepared information_schema.COLUMNS lookup with LIMIT can stop lazy
UNION ALL before all statically planned readers of the shared
mo_current_roles CTE start. Operator Reset therefore cannot release
those unstarted readers, and the next prepared execution rejects the
still-active materialized source generation.

This change makes one pipeline execution attempt the final owner of
every materialized generation it successfully opens. Operator cleanup
remains the eager path; an attempt-level deferred cleanup closes skipped
readers on success, initialization or execution errors, and panics.
Partial initialization returns only sources opened by that attempt, so
an active source owned elsewhere is never closed accidentally.

The reuse error now reports the generation and unreleased owner IDs.
Normal already-released generations use a fast no-op Close, and planner
materialization plus lazy UNION behavior remain unchanged.

## Validation

- make build
- full normal tests for ./pkg/sql/internal/materialized and
./pkg/sql/compile
- full race tests for both owning packages
- go vet for both owning packages
- repeated focused race tests for success, execution-error, panic,
cancellation, and prepared-reuse lifecycle cases
- fresh quickstart black-box execution of the exact parameterized
information_schema.COLUMNS LIMIT query across hit, miss, repeated
execution, and schema recreation
- EXPLAIN confirms mo_current_roles materialization, UNION ALL, LIMIT,
and Sink Scan reuse remain enabled
- distributed metadata regression executes the prepared query twice on
one connection

Signed-off-by: XuPeng-SH <[email protected]>
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:

issue matrixorigin#28266

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

A prepared information_schema.COLUMNS lookup with LIMIT can stop lazy
UNION ALL before all statically planned readers of the shared
mo_current_roles CTE start. Operator Reset therefore cannot release
those unstarted readers, and the next prepared execution rejects the
still-active materialized source generation.

This change makes one pipeline execution attempt the final owner of
every materialized generation it successfully opens. Operator cleanup
remains the eager path; an attempt-level deferred cleanup closes skipped
readers on success, initialization or execution errors, and panics.
Partial initialization returns only sources opened by that attempt, so
an active source owned elsewhere is never closed accidentally.

The reuse error now reports the generation and unreleased owner IDs.
Normal already-released generations use a fast no-op Close, and planner
materialization plus lazy UNION behavior remain unchanged.

## Validation

- make build
- full normal tests for ./pkg/sql/internal/materialized and
./pkg/sql/compile
- full race tests for both owning packages
- go vet for both owning packages
- repeated focused race tests for success, execution-error, panic,
cancellation, and prepared-reuse lifecycle cases
- fresh quickstart black-box execution of the exact parameterized
information_schema.COLUMNS LIMIT query across hit, miss, repeated
execution, and schema recreation
- EXPLAIN confirms mo_current_roles materialization, UNION ALL, LIMIT,
and Sink Scan reuse remain enabled
- distributed metadata regression executes the prepared query twice on
one connection

Signed-off-by: XuPeng-SH <[email protected]>

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.

2 participants