fix: allow REPLACE in binary-protocol COM_STMT_PREPARE (#25429)#25453
Merged
Conversation
…25429) COM_STMT_PREPARE is rewritten into an unquoted `prepare <name> from <sql>` and parsed via the `prepareable_stmt` grammar rule, which was missing `replace_stmt`. As a result, preparing a REPLACE statement through the MySQL binary protocol (go-sql-driver default, JDBC with useServerPrepStmts=true, etc.) failed with a 1064 syntax error, while the text-protocol `PREPARE s FROM 'replace ...'` form worked. Add `replace_stmt` to `prepareable_stmt` and regenerate the parser. The execute side already handles `*tree.Replace` for prepared statements (getPreparePlan / BuildPlan / bindAndOptimizeReplaceQuery), so no execute-side change is needed. Add parser unit tests and BVT coverage for prepared REPLACE (VALUES and SELECT sources). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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? |
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
Which issue(s) this PR fixes:
fixes #25429
What this PR does / why we need it:
Preparing a
REPLACEstatement through the MySQL binary protocol(
COM_STMT_PREPARE, i.e. go-sql-driver with default settings, JDBC withuseServerPrepStmts=true, etc.) failed with a1064syntax error:Root cause: the frontend rewrites
COM_STMT_PREPAREinto an unquotedprepare <name> from <raw sql>, which is parsed via theprepareable_stmtgrammar rule inmysql_sql.y. That rule was missingreplace_stmt(it is present only inexplainable_stmt), so the wrappedstatement failed to parse. The quoted text-protocol form
PREPARE s FROM 'replace ...'worked because it goes through theFROM STRINGrule and parses the inner statement separately.REPLACEis a preparable statement in MySQL, so this diverges from MySQLbehavior.
Fix
replace_stmttoprepareable_stmtand regenerate the parser.getPreparePlan/BuildPlan/bindAndOptimizeReplaceQueryalready handle*tree.Replaceforprepared statements (which is why the quoted text-protocol form already
worked end-to-end).
Tests
REPLACE(VALUES and SELECT sources).prepare/prepare_all.sqlfor preparedREPLACE(VALUES and SELECT sources), verified via mo-tester.
interpolateParams=false,real binary-protocol
COM_STMT_PREPARE):replace into t values (?, ?)now prepares and executes correctly.