Skip to content

fix(frontend): allow binary prepare for single SET assignment - #26694

Merged
mergify[bot] merged 5 commits into
matrixorigin:mainfrom
LeftHandCold:fix/issue-25996-binary-set-prepare
Aug 4, 2026
Merged

mergify[bot] merged 5 commits into
matrixorigin:mainfrom
LeftHandCold:fix/issue-25996-binary-set-prepare

Conversation

@LeftHandCold

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #25996

What this PR does / why we need it:

Binary COM_STMT_PREPARE wraps the client payload as PREPARE <name> FROM <statement>. The prepareable grammar admitted SELECT/DML statements but not SET, so PrepareContext("SET @binary_value = ?") failed with ERROR 1064 before parameter binding even though #26096 already supports planning and executing prepared SET expressions.

This patch admits only SET with one variable assignment in that grammar and regenerates the MySQL parser. The regression goes through the real ExecRequest(COM_STMT_PREPARE) path, verifies the retained tree.SetVar plan and parameter metadata, and confirms binary multi-assignment remains rejected.

The single-assignment boundary is intentional: prepared multi-assignment currently has a separate panic and partial-update atomicity defect tracked by #26685. This PR does not expose that known path or change SET execution semantics.

Tested with:

go test -mod=readonly ./pkg/sql/parsers/dialect/mysql -count=1

go test -mod=readonly ./pkg/frontend -count=1 -timeout=10m

go vet -mod=readonly ./pkg/sql/parsers/dialect/mysql ./pkg/frontend

go test -mod=readonly -race ./pkg/frontend -run "^TestExecRequestStmtPrepareAcceptsSetVariable$" -count=100

go test -mod=readonly -race ./pkg/frontend -run "^TestPreparedSetBinaryProtocolReportsAndReplacesParameters$" -count=100

go test -mod=readonly -race ./pkg/sql/parsers/dialect/mysql ./pkg/frontend -count=1

The parser generator completed with zero conflicts. CGo-transitive frontend commands used the repository third-party include/library and libmo linker configuration.

@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 complete on exact head 223255882c8cbad48c661967f067ec3071a59d52; no blocking finding.

The grammar change closes only the binary COM_STMT_PREPARE entry gap by admitting one SET var_assignment. Multi-assignment remains rejected before planning, so this does not expose the separate #26685 panic/partial-update path. The real ExecRequest(COM_STMT_PREPARE) regression proves the retained tree.SetVar, one parameter slot, and rejection of two assignments.

The generated parser is reproducible from mysql_sql.y (only goyacc's output-path header differs when generated into a temp file) and reports zero conflicts. Exact-head validation: owning packages list/build/vet pass; full parser and frontend tests pass; focused test passes 10x and race passes 3x; git diff --check is clean.

Q1: the test-owned session and prepared statement are closed by the existing session lifecycle; no production resource owner changes. Q2: no new wait edge. Q3: a failed multi-assignment prepare is not installed in the prepared-statement registry, so no new accumulation path.

@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 the complete diff on exact head 223255882c8cbad48c661967f067ec3071a59d52. No P0, P1, P2, or P3 findings.

The new grammar branch admits exactly one SET var_assignment for the internal binary COM_STMT_PREPARE wrapper and constructs the same tree.SetVar used by the existing prepared-SET planner/executor path. A second top-level assignment remains a syntax error before planning, so this change does not expose the separate multi-assignment panic/partial-update path tracked by #26685. I also traced prepare registration, parameter metadata, execution-time expression binding, authorization, and session cleanup; the patch does not add a resource owner, wait edge, or hot-path work outside parsing.

Validation on this head: goyacc regeneration completed with zero conflicts and matched the committed parser body; git diff --check is clean; the MySQL parser package build, vet, and full tests passed locally. All 26 GitHub checks are complete with no failing or pending check, including the frontend/owning-package CI coverage.

@XuPeng-SH

Copy link
Copy Markdown
Contributor

@Mergifyio refresh

@mergify

mergify Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

refresh

✅ Pull request refreshed

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

mergify Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-04 08:52 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ❌ Checks failed · in-place
  • 🚫 Left the queue — 2026-08-04 10:02 UTC · at 16c22842c93e2eca446c2ddab4ec58ba18180ea4

This pull request spent 1 hour 9 minutes 51 seconds in the queue, with no time running CI.

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

Reason

The merge conditions cannot be satisfied due to failing checks

Failing checks:

Hint

You may have to fix your CI before adding the pull request to the queue again.
If you update this pull request, to fix the CI, 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 ↓.

@mergify
mergify Bot merged commit 185ec3e into matrixorigin:main Aug 4, 2026
32 of 33 checks passed
@mergify mergify Bot removed the queued label Aug 4, 2026
mergify Bot pushed a commit that referenced this pull request Aug 6, 2026
Prepared multi-assignment `SET` evaluated each RHS through a derived `SELECT` in the session's shared `Process`. Cleanup after the first expression freed the outer prepared-parameter vector, so the next global parameter ordinal panicked. The recovered error also left the first session variable updated.

Changes:
- Fence the complete prepared-parameter state (`vector`, binary flags, and ownership) while a derived query frees its own resources, then restore the outer owner on every return or panic path.
- Preserve direct `SET` left-to-right semantics for prepared user-variable assignments: evaluate and apply each assignment sequentially so a later RHS observes earlier targets.
- Snapshot every unique target at statement entry and restore that original state on any later expression/apply failure or panic. Repeated/self-referential targets retain one rollback image instead of overwriting it after the first mutation.
- Reject prepared multi-assignment `SET` containing a system variable before any RHS evaluation or mutation; prepared single-system assignment remains supported.
- Add a defensive missing-parameter error instead of dereferencing a nil vector.
- Extend binary prepared `SET` from one assignment to `var_assignment_list`.
- Cover text and real binary protocol execution, rebinding, composite expressions, left-to-right visibility, repeated/self-referential targets, repeated-target rollback, numeric/string/NULL values, invalid arity, failure atomicity, connection reuse, and final ownership cleanup.

Non-goals:
- This PR does not add a general rollback framework for apply-time side effects of mixed session/global/system-variable assignments; prepared multi-assignment statements containing system variables are intentionally unsupported.

Validation:
- Base behavior: FAIL on #26694 head `16c22842c93e2eca446c2ddab4ec58ba18180ea4` — the second parameter was unavailable after derived-query cleanup, while the first target variable had already changed.
- CR falsification: FAIL before the ordering repair — both text and binary protocol regressions returned `@b = 6` instead of `42` when a later RHS referenced the earlier target.
- Runtime regression: PASS on exact head `a08036a33fc4d00c00ebc6017445795112bad1be`, covering text PREPARE/EXECUTE and real `COM_STMT_PREPARE/EXECUTE`, left-to-right visibility, repeated targets, repeated-target rollback after a later RHS failure, mixed-target prevalidation, unchanged terminal state, and connection reuse.
- Focused race: PASS on exact head, adaptive `-race -count=1` (`T=17.7s`, `B=30s`, `N=1`) for `TestIssue26685PreparedMultiSet`; Frontend owning-package race also passed once.
- Owning packages: PASS for Frontend, Process, and MySQL parser; focused build and `go vet` passed.
- BVT: PASS locally on the current built `mo-service`, `test/distributed/cases/prepare/prepare_all.sql` (394 total, 393 success, 1 existing ignore, 0 failed/abnormal).
- Preflight: `PASS semantic=PASS exact-head=a08036a33fc4d00c00ebc6017445795112bad1be diff-hash=7d4de1a3cbfd3952646614618015180bac6118eda23db83d9937b188f9852f98`.
- Diff hygiene: PASS, `git diff --check`.

QA Decision
- required: yes
- reason: user-visible SQL compatibility, a deterministic recovered panic, and session-state failure atomicity
- production_entrypoint: text PREPARE/EXECUTE and binary COM_STMT_PREPARE/EXECUTE
- automated_terminal_coverage: user/system variables' final values, left-to-right visibility, repeated/self-referential targets, repeated-target rollback, rebinding, NULL, invalid arity, failing later RHS, mixed-target rejection before mutation, single-system compatibility, connection reuse, and parameter ownership cleanup
- remaining_validation: verify text and binary drivers on a deployed build after merge, including repeated rebinding and failure-state inspection

Approved by: @heni02, @XuPeng-SH, @iamlinjunhong
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…origin#26694)

Binary `COM_STMT_PREPARE` wraps the client payload as `PREPARE <name> FROM <statement>`. The prepareable grammar admitted SELECT/DML statements but not `SET`, so `PrepareContext("SET @binary_value = ?")` failed with ERROR 1064 before parameter binding even though matrixorigin#26096 already supports planning and executing prepared SET expressions.

This patch admits only `SET` with one variable assignment in that grammar and regenerates the MySQL parser. The regression goes through the real `ExecRequest(COM_STMT_PREPARE)` path, verifies the retained `tree.SetVar` plan and parameter metadata, and confirms binary multi-assignment remains rejected.

The single-assignment boundary is intentional: prepared multi-assignment currently has a separate panic and partial-update atomicity defect tracked by matrixorigin#26685. This PR does not expose that known path or change SET execution semantics.

Tested with:

`go test -mod=readonly ./pkg/sql/parsers/dialect/mysql -count=1`

`go test -mod=readonly ./pkg/frontend -count=1 -timeout=10m`

`go vet -mod=readonly ./pkg/sql/parsers/dialect/mysql ./pkg/frontend`

`go test -mod=readonly -race ./pkg/frontend -run "^TestExecRequestStmtPrepareAcceptsSetVariable$" -count=100`

`go test -mod=readonly -race ./pkg/frontend -run "^TestPreparedSetBinaryProtocolReportsAndReplacesParameters$" -count=100`

`go test -mod=readonly -race ./pkg/sql/parsers/dialect/mysql ./pkg/frontend -count=1`

The parser generator completed with zero conflicts. CGo-transitive frontend commands used the repository third-party include/library and `libmo` linker configuration.

Approved by: @XuPeng-SH, @iamlinjunhong
VioletQwQ-0 added a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…n#26705)

Prepared multi-assignment `SET` evaluated each RHS through a derived `SELECT` in the session's shared `Process`. Cleanup after the first expression freed the outer prepared-parameter vector, so the next global parameter ordinal panicked. The recovered error also left the first session variable updated.

Changes:
- Fence the complete prepared-parameter state (`vector`, binary flags, and ownership) while a derived query frees its own resources, then restore the outer owner on every return or panic path.
- Preserve direct `SET` left-to-right semantics for prepared user-variable assignments: evaluate and apply each assignment sequentially so a later RHS observes earlier targets.
- Snapshot every unique target at statement entry and restore that original state on any later expression/apply failure or panic. Repeated/self-referential targets retain one rollback image instead of overwriting it after the first mutation.
- Reject prepared multi-assignment `SET` containing a system variable before any RHS evaluation or mutation; prepared single-system assignment remains supported.
- Add a defensive missing-parameter error instead of dereferencing a nil vector.
- Extend binary prepared `SET` from one assignment to `var_assignment_list`.
- Cover text and real binary protocol execution, rebinding, composite expressions, left-to-right visibility, repeated/self-referential targets, repeated-target rollback, numeric/string/NULL values, invalid arity, failure atomicity, connection reuse, and final ownership cleanup.

Non-goals:
- This PR does not add a general rollback framework for apply-time side effects of mixed session/global/system-variable assignments; prepared multi-assignment statements containing system variables are intentionally unsupported.

Validation:
- Base behavior: FAIL on matrixorigin#26694 head `16c22842c93e2eca446c2ddab4ec58ba18180ea4` — the second parameter was unavailable after derived-query cleanup, while the first target variable had already changed.
- CR falsification: FAIL before the ordering repair — both text and binary protocol regressions returned `@b = 6` instead of `42` when a later RHS referenced the earlier target.
- Runtime regression: PASS on exact head `a08036a33fc4d00c00ebc6017445795112bad1be`, covering text PREPARE/EXECUTE and real `COM_STMT_PREPARE/EXECUTE`, left-to-right visibility, repeated targets, repeated-target rollback after a later RHS failure, mixed-target prevalidation, unchanged terminal state, and connection reuse.
- Focused race: PASS on exact head, adaptive `-race -count=1` (`T=17.7s`, `B=30s`, `N=1`) for `TestIssue26685PreparedMultiSet`; Frontend owning-package race also passed once.
- Owning packages: PASS for Frontend, Process, and MySQL parser; focused build and `go vet` passed.
- BVT: PASS locally on the current built `mo-service`, `test/distributed/cases/prepare/prepare_all.sql` (394 total, 393 success, 1 existing ignore, 0 failed/abnormal).
- Preflight: `PASS semantic=PASS exact-head=a08036a33fc4d00c00ebc6017445795112bad1be diff-hash=7d4de1a3cbfd3952646614618015180bac6118eda23db83d9937b188f9852f98`.
- Diff hygiene: PASS, `git diff --check`.

QA Decision
- required: yes
- reason: user-visible SQL compatibility, a deterministic recovered panic, and session-state failure atomicity
- production_entrypoint: text PREPARE/EXECUTE and binary COM_STMT_PREPARE/EXECUTE
- automated_terminal_coverage: user/system variables' final values, left-to-right visibility, repeated/self-referential targets, repeated-target rollback, rebinding, NULL, invalid arity, failing later RHS, mixed-target rejection before mutation, single-system compatibility, connection reuse, and parameter ownership cleanup
- remaining_validation: verify text and binary drivers on a deployed build after merge, including repeated rebinding and failure-state inspection

Approved by: @heni02, @XuPeng-SH, @iamlinjunhong
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…origin#26694)

Binary `COM_STMT_PREPARE` wraps the client payload as `PREPARE <name> FROM <statement>`. The prepareable grammar admitted SELECT/DML statements but not `SET`, so `PrepareContext("SET @binary_value = ?")` failed with ERROR 1064 before parameter binding even though matrixorigin#26096 already supports planning and executing prepared SET expressions.

This patch admits only `SET` with one variable assignment in that grammar and regenerates the MySQL parser. The regression goes through the real `ExecRequest(COM_STMT_PREPARE)` path, verifies the retained `tree.SetVar` plan and parameter metadata, and confirms binary multi-assignment remains rejected.

The single-assignment boundary is intentional: prepared multi-assignment currently has a separate panic and partial-update atomicity defect tracked by matrixorigin#26685. This PR does not expose that known path or change SET execution semantics.

Tested with:

`go test -mod=readonly ./pkg/sql/parsers/dialect/mysql -count=1`

`go test -mod=readonly ./pkg/frontend -count=1 -timeout=10m`

`go vet -mod=readonly ./pkg/sql/parsers/dialect/mysql ./pkg/frontend`

`go test -mod=readonly -race ./pkg/frontend -run "^TestExecRequestStmtPrepareAcceptsSetVariable$" -count=100`

`go test -mod=readonly -race ./pkg/frontend -run "^TestPreparedSetBinaryProtocolReportsAndReplacesParameters$" -count=100`

`go test -mod=readonly -race ./pkg/sql/parsers/dialect/mysql ./pkg/frontend -count=1`

The parser generator completed with zero conflicts. CGo-transitive frontend commands used the repository third-party include/library and `libmo` linker configuration.

Approved by: @XuPeng-SH, @iamlinjunhong
VioletQwQ-0 added a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…n#26705)

Prepared multi-assignment `SET` evaluated each RHS through a derived `SELECT` in the session's shared `Process`. Cleanup after the first expression freed the outer prepared-parameter vector, so the next global parameter ordinal panicked. The recovered error also left the first session variable updated.

Changes:
- Fence the complete prepared-parameter state (`vector`, binary flags, and ownership) while a derived query frees its own resources, then restore the outer owner on every return or panic path.
- Preserve direct `SET` left-to-right semantics for prepared user-variable assignments: evaluate and apply each assignment sequentially so a later RHS observes earlier targets.
- Snapshot every unique target at statement entry and restore that original state on any later expression/apply failure or panic. Repeated/self-referential targets retain one rollback image instead of overwriting it after the first mutation.
- Reject prepared multi-assignment `SET` containing a system variable before any RHS evaluation or mutation; prepared single-system assignment remains supported.
- Add a defensive missing-parameter error instead of dereferencing a nil vector.
- Extend binary prepared `SET` from one assignment to `var_assignment_list`.
- Cover text and real binary protocol execution, rebinding, composite expressions, left-to-right visibility, repeated/self-referential targets, repeated-target rollback, numeric/string/NULL values, invalid arity, failure atomicity, connection reuse, and final ownership cleanup.

Non-goals:
- This PR does not add a general rollback framework for apply-time side effects of mixed session/global/system-variable assignments; prepared multi-assignment statements containing system variables are intentionally unsupported.

Validation:
- Base behavior: FAIL on matrixorigin#26694 head `16c22842c93e2eca446c2ddab4ec58ba18180ea4` — the second parameter was unavailable after derived-query cleanup, while the first target variable had already changed.
- CR falsification: FAIL before the ordering repair — both text and binary protocol regressions returned `@b = 6` instead of `42` when a later RHS referenced the earlier target.
- Runtime regression: PASS on exact head `a08036a33fc4d00c00ebc6017445795112bad1be`, covering text PREPARE/EXECUTE and real `COM_STMT_PREPARE/EXECUTE`, left-to-right visibility, repeated targets, repeated-target rollback after a later RHS failure, mixed-target prevalidation, unchanged terminal state, and connection reuse.
- Focused race: PASS on exact head, adaptive `-race -count=1` (`T=17.7s`, `B=30s`, `N=1`) for `TestIssue26685PreparedMultiSet`; Frontend owning-package race also passed once.
- Owning packages: PASS for Frontend, Process, and MySQL parser; focused build and `go vet` passed.
- BVT: PASS locally on the current built `mo-service`, `test/distributed/cases/prepare/prepare_all.sql` (394 total, 393 success, 1 existing ignore, 0 failed/abnormal).
- Preflight: `PASS semantic=PASS exact-head=a08036a33fc4d00c00ebc6017445795112bad1be diff-hash=7d4de1a3cbfd3952646614618015180bac6118eda23db83d9937b188f9852f98`.
- Diff hygiene: PASS, `git diff --check`.

QA Decision
- required: yes
- reason: user-visible SQL compatibility, a deterministic recovered panic, and session-state failure atomicity
- production_entrypoint: text PREPARE/EXECUTE and binary COM_STMT_PREPARE/EXECUTE
- automated_terminal_coverage: user/system variables' final values, left-to-right visibility, repeated/self-referential targets, repeated-target rollback, rebinding, NULL, invalid arity, failing later RHS, mixed-target rejection before mutation, single-system compatibility, connection reuse, and parameter ownership cleanup
- remaining_validation: verify text and binary drivers on a deployed build after merge, including repeated rebinding and failure-state inspection

Approved by: @heni02, @XuPeng-SH, @iamlinjunhong
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…origin#26694)

Binary `COM_STMT_PREPARE` wraps the client payload as `PREPARE <name> FROM <statement>`. The prepareable grammar admitted SELECT/DML statements but not `SET`, so `PrepareContext("SET @binary_value = ?")` failed with ERROR 1064 before parameter binding even though matrixorigin#26096 already supports planning and executing prepared SET expressions.

This patch admits only `SET` with one variable assignment in that grammar and regenerates the MySQL parser. The regression goes through the real `ExecRequest(COM_STMT_PREPARE)` path, verifies the retained `tree.SetVar` plan and parameter metadata, and confirms binary multi-assignment remains rejected.

The single-assignment boundary is intentional: prepared multi-assignment currently has a separate panic and partial-update atomicity defect tracked by matrixorigin#26685. This PR does not expose that known path or change SET execution semantics.

Tested with:

`go test -mod=readonly ./pkg/sql/parsers/dialect/mysql -count=1`

`go test -mod=readonly ./pkg/frontend -count=1 -timeout=10m`

`go vet -mod=readonly ./pkg/sql/parsers/dialect/mysql ./pkg/frontend`

`go test -mod=readonly -race ./pkg/frontend -run "^TestExecRequestStmtPrepareAcceptsSetVariable$" -count=100`

`go test -mod=readonly -race ./pkg/frontend -run "^TestPreparedSetBinaryProtocolReportsAndReplacesParameters$" -count=100`

`go test -mod=readonly -race ./pkg/sql/parsers/dialect/mysql ./pkg/frontend -count=1`

The parser generator completed with zero conflicts. CGo-transitive frontend commands used the repository third-party include/library and `libmo` linker configuration.

Approved by: @XuPeng-SH, @iamlinjunhong
VioletQwQ-0 added a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…n#26705)

Prepared multi-assignment `SET` evaluated each RHS through a derived `SELECT` in the session's shared `Process`. Cleanup after the first expression freed the outer prepared-parameter vector, so the next global parameter ordinal panicked. The recovered error also left the first session variable updated.

Changes:
- Fence the complete prepared-parameter state (`vector`, binary flags, and ownership) while a derived query frees its own resources, then restore the outer owner on every return or panic path.
- Preserve direct `SET` left-to-right semantics for prepared user-variable assignments: evaluate and apply each assignment sequentially so a later RHS observes earlier targets.
- Snapshot every unique target at statement entry and restore that original state on any later expression/apply failure or panic. Repeated/self-referential targets retain one rollback image instead of overwriting it after the first mutation.
- Reject prepared multi-assignment `SET` containing a system variable before any RHS evaluation or mutation; prepared single-system assignment remains supported.
- Add a defensive missing-parameter error instead of dereferencing a nil vector.
- Extend binary prepared `SET` from one assignment to `var_assignment_list`.
- Cover text and real binary protocol execution, rebinding, composite expressions, left-to-right visibility, repeated/self-referential targets, repeated-target rollback, numeric/string/NULL values, invalid arity, failure atomicity, connection reuse, and final ownership cleanup.

Non-goals:
- This PR does not add a general rollback framework for apply-time side effects of mixed session/global/system-variable assignments; prepared multi-assignment statements containing system variables are intentionally unsupported.

Validation:
- Base behavior: FAIL on matrixorigin#26694 head `16c22842c93e2eca446c2ddab4ec58ba18180ea4` — the second parameter was unavailable after derived-query cleanup, while the first target variable had already changed.
- CR falsification: FAIL before the ordering repair — both text and binary protocol regressions returned `@b = 6` instead of `42` when a later RHS referenced the earlier target.
- Runtime regression: PASS on exact head `a08036a33fc4d00c00ebc6017445795112bad1be`, covering text PREPARE/EXECUTE and real `COM_STMT_PREPARE/EXECUTE`, left-to-right visibility, repeated targets, repeated-target rollback after a later RHS failure, mixed-target prevalidation, unchanged terminal state, and connection reuse.
- Focused race: PASS on exact head, adaptive `-race -count=1` (`T=17.7s`, `B=30s`, `N=1`) for `TestIssue26685PreparedMultiSet`; Frontend owning-package race also passed once.
- Owning packages: PASS for Frontend, Process, and MySQL parser; focused build and `go vet` passed.
- BVT: PASS locally on the current built `mo-service`, `test/distributed/cases/prepare/prepare_all.sql` (394 total, 393 success, 1 existing ignore, 0 failed/abnormal).
- Preflight: `PASS semantic=PASS exact-head=a08036a33fc4d00c00ebc6017445795112bad1be diff-hash=7d4de1a3cbfd3952646614618015180bac6118eda23db83d9937b188f9852f98`.
- Diff hygiene: PASS, `git diff --check`.

QA Decision
- required: yes
- reason: user-visible SQL compatibility, a deterministic recovered panic, and session-state failure atomicity
- production_entrypoint: text PREPARE/EXECUTE and binary COM_STMT_PREPARE/EXECUTE
- automated_terminal_coverage: user/system variables' final values, left-to-right visibility, repeated/self-referential targets, repeated-target rollback, rebinding, NULL, invalid arity, failing later RHS, mixed-target rejection before mutation, single-system compatibility, connection reuse, and parameter ownership cleanup
- remaining_validation: verify text and binary drivers on a deployed build after merge, including repeated rebinding and failure-state inspection

Approved by: @heni02, @XuPeng-SH, @iamlinjunhong

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/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants