Skip to content

fix(txn): preserve cached plan generation across transactions - #27738

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
aptend:fix/cached-plan-ddl-fence-27659
Aug 27, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
aptend:fix/cached-plan-ddl-fence-27659

Conversation

@aptend

@aptend aptend commented Aug 27, 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 #27659

What this PR does / why we need it:

A cached prepared or session plan can outlive the transaction that compiled it. After a copy-based ALTER TABLE on another CN, using the executing transaction creation timestamp for the retained DDL fence can hide that the plan still references the old table generation.

This change:

  • binds each logical plan generation to its immutable compilation snapshot and carries it through prepared/session caches, retries, child processes, and remote fragments;
  • compares retained definition fences with that plan snapshot while preserving transaction CreateTS for rolling-restart admission;
  • adds the MORPC v32 capability gate and a final lock-boundary downgrade guard for mixed-version clusters;
  • atomically publishes or invalidates rebuilt cached generations and protects streamed result metadata from incompatible definition retries.

Validation:

  • focused prepared/session cache, retry, lock fence, remote codec, and metadata regressions;
  • full owning-package tests and race tests;
  • adaptive focused race stress;
  • relevant package build and vet.

Not run locally: live multi-CN rolling-upgrade BVT.

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

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

Approved exact head .\n\nThe fix preserves the required invariant: a reusable logical plan is bound to its compilation snapshot, ordinary retry/reset keeps that binding, and a definition-change retry publishes the rebuilt plan and new snapshot only after physical compilation succeeds. Prepared/session cache invalidation, child and remote propagation, result-metadata freezing, and the v32 lock-boundary downgrade guard cover the important ownership and mixed-version edges. The exact-head multi-CN pessimistic BVT passed, and I found no remaining correctness, lifecycle, or protocol blocker.

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

Approved exact head e6c342e6a4f5ecb78cafa3dad97aab11f7008097.

The fix preserves the required invariant: a reusable logical plan is bound to its compilation snapshot, ordinary retry/reset keeps that binding, and a definition-change retry publishes the rebuilt plan and new snapshot only after physical compilation succeeds. Prepared/session cache invalidation, child and remote propagation, result-metadata freezing, and the v32 lock-boundary downgrade guard cover the important ownership and mixed-version edges. The exact-head multi-CN pessimistic BVT passed, and I found no remaining correctness, lifecycle, or protocol blocker.

@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-reviewed exact head e6c342e6a4f5ecb78cafa3dad97aab11f7008097 against base b0ae66c04d9a67175d2dfb8bf1c777fb888e1430.

The fix addresses #27659 at the actual violated invariant: the retained DDL fence is compared with the immutable logical-plan generation snapshot, while transaction CreateTS keeps its separate rolling-restart role. Prepared and session caches carry plan + snapshot as one generation; Reset and data-only retry preserve it; a definition retry publishes a newly compiled plan/snapshot only after successful physical compilation and invalidates stale frontend topology on every failed rebuild path.

Lifecycle/unhappy-path audit:

  • Q1 ownership: Compile owns the generation binding; Process only transports it and clears it at Release. Cached prepared topology, runtime specialization, and borrowed session-cache AST retain distinct release owners; the invalidation paths avoid double Release.
  • Q2 termination: definition retry uses the existing bounded retry machinery. Protocol rollback is rechecked at the final lock boundary; RC rebuilds locally, while SI preserves WW-conflict semantics.
  • Q3 growth: session-cache timestamps are bounded by the existing LRU entries, prepared state adds constant-size fields, and no retry-owned generation is retained after terminal failure.

Remote child/codec propagation and old-sender fallback are coherent. Result metadata is frozen before streaming and incompatible rebuilt schemas fail before row execution; RETURNING delays metadata until its attempt spool succeeds. The ordinary path adds no RPC, polling, catalog lookup, or unconditional rebuild; current generations omit the optional lock payload.

I reviewed the full non-generated diff and focused tests, verified git diff --check, and exact-head CI is green, including multi-CN pessimistic and Proxy BVT. I found no blocking correctness, performance, race/lifecycle, hang, or leak issue.

@mergify mergify Bot added the queued label Aug 27, 2026
@mergify

mergify Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-27 08:45 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🚫 Left the queue — 2026-08-27 08:48 UTC · at e6c342e6a4f5ecb78cafa3dad97aab11f7008097

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

Reason

Pull request #27738 has been dequeued

Queue conditions are not satisfied:

  • any of: [🔀 queue conditions]
    • all of: [📌 queue conditions of queue rule main]
      • #review-threads-unresolved = 0 [🛡 GitHub branch protection]

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.

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

@iamlinjunhong iamlinjunhong 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 e6c342e6a4f5ecb78cafa3dad97aab11f7008097 against merge-base b0ae66c04d9a67175d2dfb8bf1c777fb888e1430, including the clean merge with current origin/main (424fe3d821e45fe883ab93af5b404d77686d05a0). I found no P0/P1 blocker. Two P2 findings are attached: one correctness gap for SELECT ... INTO arity after a definition retry, and one steady-state plan-cache hit allocation.

Comment thread pkg/sql/compile/compile2.go Resolved
Comment thread pkg/frontend/mysql_cmd_executor.go Resolved
@mergify

mergify Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-27 12:19 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-08-27 12:30 UTC · at 355d8271575961582440935cf7cfc8187a6821fe

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

Waiting for
  • 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
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
All conditions
  • 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
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]

Reason

Pull request #27738 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 7469684 into matrixorigin:main Aug 27, 2026
20 of 21 checks passed
@mergify mergify Bot added dequeued and removed queued labels Aug 27, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…origin#27738)

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

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

A cached prepared or session plan can outlive the transaction that
compiled it. After a copy-based ALTER TABLE on another CN, using the
executing transaction creation timestamp for the retained DDL fence can
hide that the plan still references the old table generation.

This change:
- binds each logical plan generation to its immutable compilation
snapshot and carries it through prepared/session caches, retries, child
processes, and remote fragments;
- compares retained definition fences with that plan snapshot while
preserving transaction CreateTS for rolling-restart admission;
- adds the MORPC v32 capability gate and a final lock-boundary downgrade
guard for mixed-version clusters;
- atomically publishes or invalidates rebuilt cached generations and
protects streamed result metadata from incompatible definition retries.

Validation:
- focused prepared/session cache, retry, lock fence, remote codec, and
metadata regressions;
- full owning-package tests and race tests;
- adaptive focused race stress;
- relevant package build and vet.

Not run locally: live multi-CN rolling-upgrade BVT.

---------

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
…origin#27738)

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

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

A cached prepared or session plan can outlive the transaction that
compiled it. After a copy-based ALTER TABLE on another CN, using the
executing transaction creation timestamp for the retained DDL fence can
hide that the plan still references the old table generation.

This change:
- binds each logical plan generation to its immutable compilation
snapshot and carries it through prepared/session caches, retries, child
processes, and remote fragments;
- compares retained definition fences with that plan snapshot while
preserving transaction CreateTS for rolling-restart admission;
- adds the MORPC v32 capability gate and a final lock-boundary downgrade
guard for mixed-version clusters;
- atomically publishes or invalidates rebuilt cached generations and
protects streamed result metadata from incompatible definition retries.

Validation:
- focused prepared/session cache, retry, lock fence, remote codec, and
metadata regressions;
- full owning-package tests and race tests;
- adaptive focused race stress;
- relevant package build and vet.

Not run locally: live multi-CN rolling-upgrade BVT.

---------

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
…origin#27738)

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

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

A cached prepared or session plan can outlive the transaction that
compiled it. After a copy-based ALTER TABLE on another CN, using the
executing transaction creation timestamp for the retained DDL fence can
hide that the plan still references the old table generation.

This change:
- binds each logical plan generation to its immutable compilation
snapshot and carries it through prepared/session caches, retries, child
processes, and remote fragments;
- compares retained definition fences with that plan snapshot while
preserving transaction CreateTS for rolling-restart admission;
- adds the MORPC v32 capability gate and a final lock-boundary downgrade
guard for mixed-version clusters;
- atomically publishes or invalidates rebuilt cached generations and
protects streamed result metadata from incompatible definition retries.

Validation:
- focused prepared/session cache, retry, lock fence, remote codec, and
metadata regressions;
- full owning-package tests and race tests;
- adaptive focused race stress;
- relevant package build and vet.

Not run locally: live multi-CN rolling-upgrade BVT.

---------

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/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants