Skip to content

fix(frontend): restore compiler context for prepared multi-statements - #27471

Merged
XuPeng-SH merged 6 commits into
matrixorigin:mainfrom
daviszhen:fix/issue-26766-prepared-multistatement-v2
Aug 22, 2026
Merged

XuPeng-SH merged 6 commits into
matrixorigin:mainfrom
daviszhen:fix/issue-26766-prepared-multistatement-v2

Conversation

@daviszhen

@daviszhen daviszhen commented Aug 22, 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 #26766

What this PR does / why we need it:

The previous fix guarded a released compiler process, but a nested synthetic SELECT used for SET @user_var = expr could still leave the session compiler context pointing at a closed ExecCtx. A later EXECUTE in the same CLIENT_MULTI_STATEMENTS packet then observed a nil request context and panicked in context.WithValue while attaching plan counters.

This change:

  • restores the caller's TxnCompilerContext after synthetic SET-expression evaluation;
  • falls back to the current request (or context.Background() as a final defensive fallback) before attaching build-plan counters;
  • adds regressions for the nil process/nil context path and for planning the next statement after SET evaluation.

@daviszhen
daviszhen requested a review from XuPeng-SH as a code owner August 22, 2026 03:19
@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 →

@daviszhen

Copy link
Copy Markdown
Contributor Author

Thanks for the follow-up verification. The remaining panic was caused by the closed temporary ExecCtx created while evaluating the preceding SET @x=41 expression: the next statement saw both a nil process and a nil request context.

PR #27471 addresses both sides:

  • getExprValueWithPrepareMeta restores the caller's TxnCompilerContext after the synthetic SELECT completes, so a later statement reuses the live request/process context.
  • buildPlanWithPrepareMode defensively falls back to the current request/background context before perfcounter.AttachBuildPlanMarkKey, so a nil context cannot reach context.WithValue.

The regression now evaluates a SET expression, plans the next statement through the same compiler context, and separately covers a nil process plus nil context. Verified with:

  • go test ./pkg/frontend -count=1
  • go test -race ./pkg/frontend -run 'TestBuildPlanWithPrepareModeAllowsMissingCompilerProcess|TestGetExprValue$' -count=1

Could you please re-review the new PR against the original multi-statement SET @x=41; EXECUTE ... USING @x path?

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

Approved on exact HEAD f88267a.

I traced the temporary ExecCtx ownership through normal return and all early-error paths: the synthetic SELECT still owns and closes its temporary context, while the defer restores the caller context afterward; the planning fallback prevents a nil request context from reaching the tracing helpers.

Independent verification:

  • original CLIENT_MULTI_STATEMENTS protocol reproduction passed: SET @x=41; EXECUTE ... USING @x set @A to 41 and the same connection remained reusable;
  • focused frontend tests passed;
  • the same focused tests passed under -race;
  • diff check passed.

@mergify

mergify Bot commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

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

@mergify

mergify Bot commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-22 13:23 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-08-22 13:58 UTC · at c72cf6068b6e122570b59658fe83bd17485b8ac3

This pull request spent 34 minutes 52 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 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 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]
  • 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

Pull request #27471 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.

Failing checks:

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 48e4601 into matrixorigin:main Aug 22, 2026
25 of 26 checks passed
@mergify mergify Bot added dequeued and removed queued labels Aug 22, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…matrixorigin#27471)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue matrixorigin#26766

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

The previous fix guarded a released compiler process, but a nested
synthetic SELECT used for `SET @user_var = expr` could still leave the
session compiler context pointing at a closed `ExecCtx`. A later
`EXECUTE` in the same `CLIENT_MULTI_STATEMENTS` packet then observed a
nil request context and panicked in `context.WithValue` while attaching
plan counters.

This change:

- restores the caller's `TxnCompilerContext` after synthetic
SET-expression evaluation;
- falls back to the current request (or `context.Background()` as a
final defensive fallback) before attaching build-plan counters;
- adds regressions for the nil process/nil context path and for planning
the next statement after SET evaluation.

---------

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
…matrixorigin#27471)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue matrixorigin#26766

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

The previous fix guarded a released compiler process, but a nested
synthetic SELECT used for `SET @user_var = expr` could still leave the
session compiler context pointing at a closed `ExecCtx`. A later
`EXECUTE` in the same `CLIENT_MULTI_STATEMENTS` packet then observed a
nil request context and panicked in `context.WithValue` while attaching
plan counters.

This change:

- restores the caller's `TxnCompilerContext` after synthetic
SET-expression evaluation;
- falls back to the current request (or `context.Background()` as a
final defensive fallback) before attaching build-plan counters;
- adds regressions for the nil process/nil context path and for planning
the next statement after SET evaluation.

---------

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
…matrixorigin#27471)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue matrixorigin#26766

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

The previous fix guarded a released compiler process, but a nested
synthetic SELECT used for `SET @user_var = expr` could still leave the
session compiler context pointing at a closed `ExecCtx`. A later
`EXECUTE` in the same `CLIENT_MULTI_STATEMENTS` packet then observed a
nil request context and panicked in `context.WithValue` while attaching
plan counters.

This change:

- restores the caller's `TxnCompilerContext` after synthetic
SET-expression evaluation;
- falls back to the current request (or `context.Background()` as a
final defensive fallback) before attaching build-plan counters;
- adds regressions for the nil process/nil context path and for planning
the next statement after SET evaluation.

---------

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/enhancement size/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants