[fix](fe) Fix prepared statement forwarding losing param types on cached execute - #67982
Open
Asthenia0412 wants to merge 1 commit into
Open
Asthenia0412 wants to merge 1 commit into
Asthenia0412 wants to merge 1 commit into
Conversation
…hed execute ### What problem does this PR solve? Issue Number: close apache#65848 Problem Summary: A prepared write statement executed on a non-master FE and forwarded to the master FE fails with NoSuchElementException (errCode 1105) on cached COM_STMT_EXECUTE. The forwarded statement is re-prepared on the master, which never sees the parameter types. When the client issues a cached repeat execute (new_params_bind_flag == 0), the parameter types are omitted from the packet, so the master cannot decode the parameter values. This commit embeds the parameter types known from the first execute into the forwarded COM_STMT_EXECUTE buffer and sets new_params_bind_flag, so the master can decode the parameter values. The buffer keeps the standard MySQL packet layout, so older masters accept it unchanged. ### Release note None ### Check List (For Author) - Test: Unit test (MysqlConnectProcessorPreparedStmtForwardTest) - Behavior changed: No - Does this need documentation: No
Author
|
cc @wudi @morrySnow PTAL, thanks! |
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
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 problem does this PR solve?
Issue Number: close #65848
Problem Summary:
A prepared write statement executed on a non-master FE and forwarded to the master FE fails with
NoSuchElementException(errCode 1105) on cachedCOM_STMT_EXECUTE.Reproduction:
PREPARE/EXECUTEanINSERT ... VALUES (?, ...)statement (the first execute sendsnew_params_bind_flag = 1with the parameter types).new_params_bind_flag = 0, so the parameter types are omitted from the packet.COM_STMT_EXECUTEto the master FE. The master re-prepares the statement and never sees the parameter types, so it cannot decode the parameter values and fails.Root cause:
In
MysqlConnectProcessor.handleExecute, the forwardedCOM_STMT_EXECUTEbuffer is set before the parameter types are parsed. On a cached repeat execute the client omits the types (new_params_bind_flag == 0), and the forwarded buffer contains only the null bitmap and the parameter values, so the master cannot decode them.Fix:
When a cached execute omits the parameter types, embed the types known from the first execute into the forwarded buffer and set
new_params_bind_flag = 1. The buffer keeps the standard MySQLCOM_STMT_EXECUTElayout (null bitmap | flag | parameter types | parameter values), so older masters accept it unchanged. Zero-parameter executes keep forwarding the raw (empty) buffer.Release note
None
Check List (For Author)
MysqlConnectProcessorPreparedStmtForwardTestcovering cached execute, first execute and zero-parameter cases.