Skip to content

[fix](fe) Fix prepared statement forwarding losing param types on cached execute - #67982

Open
Asthenia0412 wants to merge 1 commit into
apache:masterfrom
Asthenia0412:fix_prepared_stmt_forward_placeholder_types
Open

Asthenia0412 wants to merge 1 commit into
apache:masterfrom
Asthenia0412:fix_prepared_stmt_forward_placeholder_types

Conversation

@Asthenia0412

Copy link
Copy Markdown

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 cached COM_STMT_EXECUTE.

Reproduction:

  1. Connect to a non-master FE with a MySQL client supporting prepared statements.
  2. PREPARE / EXECUTE an INSERT ... VALUES (?, ...) statement (the first execute sends new_params_bind_flag = 1 with the parameter types).
  3. Run the same prepared statement again without re-prepare. The client sends a cached execute with new_params_bind_flag = 0, so the parameter types are omitted from the packet.
  4. Because the statement is a write statement, the follower forwards COM_STMT_EXECUTE to 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 forwarded COM_STMT_EXECUTE buffer 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 MySQL COM_STMT_EXECUTE layout (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)

  • Test: Unit test MysqlConnectProcessorPreparedStmtForwardTest covering cached execute, first execute and zero-parameter cases.
  • Behavior changed: No
  • Does this need documentation: No

…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
@Asthenia0412

Copy link
Copy Markdown
Author

cc @wudi @morrySnow PTAL, thanks!

@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Prepared INSERT forwarded from a non-master FE fails with NoSuchElementException (errCode 1105) on cached COM_STMT_EXECUTE

2 participants