Skip to content

fix(frontend): preserve params across prepared multi-SET - #26705

Merged
mergify[bot] merged 7 commits into
matrixorigin:mainfrom
VioletQwQ-0:codex/issue-26685-prepared-multiset
Aug 6, 2026
Merged

mergify[bot] merged 7 commits into
matrixorigin:mainfrom
VioletQwQ-0:codex/issue-26685-prepared-multiset

Conversation

@VioletQwQ-0

@VioletQwQ-0 VioletQwQ-0 commented Aug 4, 2026 •

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • BUG

Which issue(s) this PR fixes:

issue #26685

What this PR does / why we need it:

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 fix(frontend): allow binary prepare for single SET assignment #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

@mergify mergify Bot added the kind/bug Something isn't working label Aug 4, 2026
@matrix-meow matrix-meow added the size/XXL Denotes a PR that changes 2000+ lines label Aug 4, 2026
@VioletQwQ-0
VioletQwQ-0 marked this pull request as ready for review August 5, 2026 02:39

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

Reviewed exact head 30c68fa672a13acc3077644ae0dc01d9f101644f. The previous left-to-right visibility blocker is fixed, and the normal text/binary regressions pass. One failure-atomicity blocker remains.

[P1] Snapshot the effective mutation set, not only assign.Name

The prepared-multi preflight treats every assignment with assign.System == false as a rollback-safe user-variable write. However, applyAssignment dispatches several special SET operations only by the lower-cased name, without checking assign.System. Consequently, the syntactic user assignment @names reaches the name == "names" branch and expands into writes to character_set_client, character_set_connection, and character_set_results, while the rollback snapshot contains only names and the other syntactic assignment names.

I reproduced this on this exact head through the public text PREPARE path:

set @character_set_client = 'client-before',
    @character_set_connection = 'connection-before',
    @character_set_results = 'results-before';
prepare p from
  'set @names = ?, @failure = (select v from values_for_error)';
set @input = 'mutated';
execute p using @input;

With values_for_error containing two rows, the second RHS correctly fails with Subquery returns more than 1 row, but all three character-set variables remain mutated; the expected result is the three *-before values. Thus a failed prepared multi-SET still leaves partial session mutation, which is the core contract of #26685.

The same dispatch/snapshot mismatch also applies to reserved user-variable spellings such as @clear_privilege_cache, @enable_privilege_cache, @optimizer_hints, and the runtime-filter knobs: those branches can mutate cache/session/runtime state that the user-variable map rollback cannot restore.

Please make the prepared-multi path distinguish ordinary user-variable assignments from special SET operations before applying them. In particular, special handlers should be guarded by the actual assignment kind, and unsupported/non-rollbackable operations should be rejected before the first mutation (or their complete effective target/side-effect set must be included in the rollback plan). Please add both text- and binary-protocol regressions with a later RHS failure for this reserved-name case.

@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

Addressed the current-head CHANGES_REQUESTED finding on 5eb2f91.

  • SET NAMES now carries an explicit syntax-level assignment-kind marker; syntactic user variables such as @NAMEs remain ordinary user assignments.
  • Every other name-based special handler now requires a system assignment, so reserved user-variable spellings cannot mutate privilege-cache, optimizer, runtime-filter, aggregate, or character-set side state.
  • Prepared multi-SET prevalidation rejects syntax-level SET NAMES before mutation, while direct SET NAMES and prepared single-system SET behavior remain unchanged.
  • Text PREPARE/EXECUTE and binary COM_STMT_PREPARE/EXECUTE regressions prove complete failure atomicity: after a later RHS error, @NAMEs and all three character-set targets retain their statement-entry values. The same focused tests fail on the old production implementation and pass on this head.
  • Added parser assignment-kind coverage for every special-handler family and extended the canonical prepare BVT terminal assertions.

Validation on the exact committed head: focused and full parser/process/frontend/issues packages PASS; go build PASS; go vet PASS; git diff --check PASS; schema-v6 semantic preflight PASS. Exact-head CI is now pending.

@XuPeng-SH please re-review the updated head.

@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 5eb2f9143806bd77924c7704403d98b5f6f2bef8 against merge-base 09e02eea38bfa87e4c4333ffb57b370091136bc8 (with current origin/main at a3f3f06fec231b595db5b9ad1a6b347bc067b83e).

Findings: none (P0–P3).

I traced the prepared-parameter ownership path through detach/borrow/nested cleanup/restore, the sequential multi-assignment evaluation and rollback paths (including repeated targets, errors, and panic unwinding), the parser assignment-kind changes, both text and binary prepare entry points, and the focused/BVT coverage. The prior left-to-right visibility and reserved user-variable dispatch blockers are closed on this head. The current main merge is clean, and all 26 reported checks are completed with accepted conclusions.

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

Reviewed exact head 5eb2f9143806bd77924c7704403d98b5f6f2bef8.

The two previous blockers are closed on this head:

  • Prepared multi-user-variable assignments now preserve direct SET's left-to-right visibility while retaining statement-entry snapshots for error and panic rollback, including repeated/self-referential targets.
  • Special SET behavior is now selected by syntax/assignment kind (SetNames or System), not merely by a reserved spelling, so user variables such as @names and the other handler-shaped names cannot escape the rollback set through unrelated session/runtime side effects.

I also traced the prepare-parameter ownership lifecycle through detach -> non-owning borrow -> nested Process.Free -> restore. The nested cleanup cannot free the outer owned parameter vector, and restoration is deferred across cleanup panics. The nil/bounds guard in GetPrepareParamsAt closes the reported crash path.

Local exact-head validation passed:

  • TestIssue26685PreparedMultiSet through both text PREPARE/EXECUTE and binary COM_STMT_PREPARE/COM_STMT_EXECUTE, covering rebinding/NULL, sequential visibility, repeated targets, late RHS failure rollback, reserved user-variable names, mixed system-variable rejection, and connection reuse.
  • Focused parser assignment-kind, Process ownership/nil-parameter, and frontend multi-SET prepare tests.
  • git diff --check.

Current GitHub checks are complete with no failures. No blocking findings remain.

@mergify

mergify Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-06 06:45 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-08-06 07:38 UTC · at 1b06dde6d6c931836bab4505a0e597ec6aa94fe1 · squash

This pull request spent 53 minutes 28 seconds in the queue, including 42 minutes 18 seconds running CI.

Required conditions to merge
  • #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 / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • 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

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants