Skip to content

fix(parser): preserve executable comments across statement splits - #30177

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
iamlinjunhong:fix/30154-executable-comment-split
Oct 14, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
iamlinjunhong:fix/30154-executable-comment-split

Conversation

@iamlinjunhong

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:

What this PR does / why we need it:

Executable comments can contain several parsed statements. Splitting at an internal statement delimiter currently leaves unmatched wrappers, for example /*!50000 select 1 and select 2 */. Consumers that reparse these fragments can report a syntax error after an earlier statement has executed.

Balance executable-comment wrappers at grammar-owned statement boundaries and retain each fragment's original source span. Scheduling and source classification use those spans to keep ordinary source markers attached to the correct statement, including cache hits. Existing string split APIs, single-statement comment text, compound boundaries and empty-fragment conventions are preserved.

SQLMode staged execution carries the raw unconsumed suffix and executable-comment context, then parses the next statement under the updated session mode. It balances only the emitted statement and avoids repeatedly copying the remaining query. Parser reset and error paths keep this state local to the current request.

Validation on Darwin/arm64 with Go 1.27.1:

  • Clean-base public Parse/Split/reparse probe confirms broken fragments. The minimal default service accepts the two plain scalar issue queries; a wrapped SET sql_mode reproduces error 1064, including a partial result with an ordinary prefix.
  • Full owning MySQL parser, parsers and frontend package tests pass.
  • Focused regressions cover independently parseable fragments and ordered AST equivalence, quoted terminators, SQL modes, compounds/empty boundaries, raw-span rejection, source markers, fresh/cache scheduling, records and rewrite hints.
  • Existing single-CN frontend fixture sends each query as one COM_QUERY, verifies all result sets for the issue inputs and SQLMode continuations in two bounded passes, and checks recovery after an invalid continuation and session-mode restoration. No additional cluster or table fixture.
  • Scoped gofmt, go vet and configured incremental lint pass (0 lint issues).

Work and copying remain linear in query bytes and fragment count. Ordinary fragments remain raw string slices; additional source metadata is bounded per fragment, and wrapper copies are limited to affected fragments. No persisted or wire-format change. Remote CI is pending and is not claimed to pass. Issue verification remains with the reporter after merge.

@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 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: fbb89c716db6a18fa47f7c631f763dfbf1211ab1

Review completed. Read the assessment.

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

mo-bot review · mo-bot-local · review

Commit: fbb89c716db6a18fa47f7c631f763dfbf1211ab1

Assessment: approve

Reviewed the complete nine-file delta, callers, tests, and supplied comments. The design appropriately keeps statement boundaries in the parser, supplies raw spans for source classification, and preserves executable-comment context across SQL-mode transitions without copying the remaining query repeatedly. This restores independently parseable fragments without introducing a competing frontend splitter. Error cleanup, parser reuse, cached scheduling, and existing empty/compound-statement contracts are covered. The bounded allocation increase is justified by the correctness improvement. No actionable findings remain.

Model: gpt-6-astra / xhigh

Session: 01a12d8f-8e48-7622-ad17-b605f08450ce · slot 1 · generation 0

Validation:

  • Preflight passed. Verified 192 native inputs and 46 retained artifact hashes against compatible repository-owned build provenance. Source remained unchanged at the assigned HEAD.

  • Focused parser tests passed. An additional diagnostic matrix passed 23,536 accepted input/mode combinations, checking source spans, independently reparsed fragments, ordered AST equivalence, and continuation parsing.

  • Focused frontend tests passed for fresh/cached scheduling, source markers, rewrite policies, SQL-mode staging, and invalid spans. The embedded TestRunSQLWithFrontend passed real COM_QUERY checks across two rounds, including mode-sensitive continuations, invalid-continuation recovery, and mode restoration.

  • Three-sample base/head split benchmarks covered SELECT, INSERT, CREATE TABLE, five statements, and a 64 KiB literal. Timings were similar; the public string-split API added one allocation, including 48 bytes for ordinary single statements and 208 bytes for five statements.

  • Commands, source fingerprints, exit receipts, log hashes, probe inputs, and benchmark results are reconciled in /home/xupeng/.local/state/mo-bot/jobs/fcdc73fa6a54a1b7f29cab1b/attempt-1/validation-audit.json. One benchmark setup attempt failed before execution because its diagnostic file was absent; the corrected run passed.

Limitations:

  • Frozen CI reports success, but raw CI logs and exact-head worker validation artifacts were not supplied; local checks provide direct behavioral evidence.

  • The full linked issue #30154 text was absent. Its executable-comment failure contract, reproduced in the PR description, was reviewed and exercised.

  • Microbenchmarks measure split API costs, not end-to-end SQL throughput or concurrent workload performance.

@mergify mergify Bot added the queued label Oct 14, 2026
@mergify

mergify Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-14 14:22 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-10-14 14:47 UTC · at add269d6d99814d239b69062bb7ffdd7b984114a

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

Reason

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

Waiting for any of
  • check-neutral = CI Required
  • check-skipped = CI Required
  • check-success = CI Required
All conditions

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

This branch had an error being deployed

1 failed deployment
ci — add269d6 Deployed Oct 14, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

3 participants