fix(frontend): locate PREPARE delimiter by token#25919
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
The token-based approach fixes the reported fromx case, but one supported token layout still stores malformed inner SQL. Details are attached inline.
gouhongshen
left a comment
There was a problem hiding this comment.
Codex automated review
The token-based extraction fixes the reported basic case, but remains incorrect for valid MySQL executable-comment syntax.
P2 - Account for executable-comment boundaries after FROM (pkg/frontend/mysql_cmd_executor.go:1559)
For valid input prepare fromx /*! from */ select 1, Scan returns the FROM token inside the executable comment with scanner.Pos immediately after from, before the closing */. The parser subsequently consumes that terminator and builds the expected select 1 AST, but this slice produces */ select 1. Consequently the prepared statement stores malformed SQL that can reach recording and rebuild paths. Derive the source offset past the executable-comment boundary and add an end-to-end regression for this layout.
gouhongshen
left a comment
There was a problem hiding this comment.
Codex automated review
The reported delimiter bug and simple executable-comment case are fixed, but executable-comment boundary detection still corrupts valid inner SQL containing */ inside a quoted string.
P2 - Find the executable-comment terminator lexically (pkg/frontend/mysql_cmd_executor.go:1561)
When FROM is tokenized inside /*! ... */, this uses strings.Index to find the first */ bytes. The parser's scanner instead consumes quoted strings while CommentFlag is set, so prepare fromx /*! from select 'x*/y' */ is accepted with the real terminator at the end. This code stops at the */ inside the string and constructs malformed SQL such as select 'x y' */, causing the stored/precompiled statement to diverge from the parsed AST or fail preparation. Derive the boundary using scanner state and add a regression test.
|
@gouhongshen @XuPeng-SH Addressed the executable-comment boundary CR in 25226fb. The frontend no longer searches raw bytes for |
gouhongshen
left a comment
There was a problem hiding this comment.
Codex automated review
No findings. The token-based extraction fixes the prior substring bug and correctly handles executable-comment boundaries, including quoted */; existing review findings are addressed. Focused tests could not run locally because go is unavailable, but CI is passing.
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #25900
What this PR does / why we need it:
doPrepareStmtpreviously searched for the firstfromsubstring in the original SQL. A statement name such asfromxwas mistaken for the delimiter, so the cached inner SQL becamefrom select 1.This PR:
Validation:
go test ./pkg/frontend -count=1go test -race ./pkg/frontend -run '^(TestHandlePrepareStmtNameContainingFrom|TestExtractPrepareStmtSQL|TestExtractPrepareStmtSQLRejectsInvalidInput)$' -count=1go vet ./pkg/frontendgo build ./pkg/frontendgit diff --check