Skip to content

[Bug]: Protocol-level prepared statements fail with mysql-connector-python prepared cursor #25423

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Searched open/all issues for:

  • "COM_STMT_PREPARE"
  • "binary protocol"
  • "mysql.connector"
  • "prepared=True"
  • "MySQL server has gone away" "prepared"

Related but not duplicate:

Branch Name

main

Commit ID

51656deb6003

Other Environment Information

  • MatrixOne: select version() returns 8.0.30-MatrixOne-v1.3.0
  • MySQL comparison: 8.0.45
  • Client: mysql-connector-python in Python, using cursor(prepared=True).
  • Text-protocol queries from the same connector work against MatrixOne.

Actual Behavior

Protocol-level prepared statements fail against MatrixOne. A simple select ? + ? using mysql-connector-python with cursor(prepared=True) returns:

DatabaseError 2006 (HY000): MySQL server has gone away

The same query succeeds against MySQL 8.0.45 and returns 3.

Control check against MatrixOne:

  • mysql CLI text protocol works: select version(), 1+2 returns normally.
  • mysql-connector-python non-prepared cursor also works: cursor(prepared=False).execute('select %s + %s', (1, 2)) returns 3.

So this appears specific to the MySQL protocol prepared-statement path (COM_STMT_PREPARE / binary protocol), not a general connection or SQL execution failure.

Expected Behavior

Same as MySQL: protocol-level prepared statements should prepare and execute successfully. This is needed by MySQL-compatible drivers and applications that use server-side prepared statements.

Steps to Reproduce

import mysql.connector

# MySQL succeeds with the same code.
cn = mysql.connector.connect(
    user='dump',
    password='111',
    host='127.0.0.1',
    port=7002,
    connection_timeout=5,
)

cur = cn.cursor(prepared=True)
cur.execute('select ? + ?', (1, 2))
print(cur.fetchall())
cur.close()
cn.close()

MatrixOne result:

DatabaseError 2006 (HY000): MySQL server has gone away

MySQL 8.0.45 result:

[(3.0,)]

Additional information

This was found during Model 14 prepared-statement compatibility exploration. SQL-level PREPARE s FROM ... was tested separately; this issue is specifically for driver-level prepared statements using the MySQL binary protocol.

Activity

  1. added this to the MO-202607 milestone on Jul 3, 2026
  2. added
    kind/bug
    on Jul 3, 2026
  3. added theissue type on Jul 3, 2026
  4. added
    severity/s0
    and removed on Jul 4, 2026
  5. hiSandog commented on Jul 6, 2026

    @hiSandog

    A useful test here would cover both the normal "COM_STMT_PREPARE" path and the edge case from this report. That should make it clear whether the fix belongs in input normalization/validation, configuration forwarding, or the lower-level execution path.

  6. ck89119 commented on Jul 23, 2026

    @ck89119
    Contributor

    Verified on the latest mo/main at 1ac64a870e2c0a6344c1dc43a6d1dbf39c907385.

    The original reproduction no longer fails:

    • Client: mysql-connector-python 9.4.0
    • Cursor: cursor(prepared=True)
    • SQL: select ? + ?
    • Parameters: (1, 2)
    • Result: [(3.0,)]

    The connection remained healthy; there was no DatabaseError 2006 or disconnect during COM_STMT_PREPARE / COM_STMT_EXECUTE.

    Additional validation on the same main commit:

    • TestIssue25753PreparedNumericProtocolLifecycle passed. This exercises the real TCP COM_STMT_PREPARE -> COM_STMT_EXECUTE -> COM_STMT_CLOSE lifecycle, statement reuse, parameter transport types, NULL, conversion-error recovery, and closed-statement behavior.
    • TestPreparedNumericContextParameterTypes passed, including the original select ? + ? planner case with both parameters resolved to DOUBLE.
    • make build passed.
    • The merge commits of fix(plan): resolve prepared numeric expression types #25788 (96847b5a63642c45c541b96055e5320f9c04a295) and test(frontend): cover prepared numeric protocol lifecycle #25893 (c3a679182e0f73dae9c20174f1d592a8dbd81c0f) are both ancestors of the tested mo/main commit.

    Conclusion: the issue is fixed on current main. #25788 contains the numeric parameter-type fix, and #25893 provides the protocol-level regression coverage. This issue can be closed as fixed.

  7. Ariznawlll commented on Jul 23, 2026

    @Ariznawlll
    CollaboratorAuthor

    最新 main 验证结果:通过

    测试版本:MatrixOne main@ebd05ba52f0d08afb4225e7b4b2e97e8030c057d

    测试步骤

    1. 使用真实 MySQL 二进制协议客户端 mysql-connector-python 创建 prepared=True cursor。
    2. 准备并执行 select ? + ?,读取结果。
    3. 在 motr 中使用 Go database/sql 建立真实协议连接,连续执行 prepared statement 20 次,并在执行后检查连接仍可用。

    实际结果

    • Python prepared cursor 返回 [(3.0,)],连续 3 轮通过。
    • motr 协议场景每轮连续执行 20 次均正确,连接健康检查通过。
    • motr 整体场景连续执行 10 轮均通过。

    回归用例

    • motr PR #61
    • 14_issue_regression.issue_25423_protocol_prepared_cursor
    • motr commit:5c7c1e5bbfa9f5f03c339a34fb931a4a2e2a946d

    结论:prepared cursor 的二进制协议执行已恢复正常。

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

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions