Skip to content

[Bug]: DEALLOCATE PREPARE silently succeeds for an unknown statement #25978

Closed

Description

@Ariznawlll

Summary

DEALLOCATE PREPARE silently succeeds when the named prepared statement does not exist or has already been deallocated.

Tested version

main at 3046f14d94b3f1a25839eeeb65729b64f85ac647.

Reproduction

DEALLOCATE PREPARE does_not_exist;

Also:

PREPARE s FROM 'SELECT 1';
DEALLOCATE PREPARE s;
DEALLOCATE PREPARE s;

Actual result

Both statements complete successfully without an error. The missing-name case reproduces 3/3 times.

Expected result

Return an unknown prepared statement error. MySQL 8.0.45 returns:

ERROR 1243 (HY000): Unknown prepared statement handler (...) given to DEALLOCATE PREPARE

Root cause

doDeallocate builds a deallocate plan and then calls Session.RemovePrepareStmt. RemovePrepareStmt checks whether an entry exists only to close it, but unconditionally deletes the map key and returns no status. As a result, doDeallocate cannot distinguish a successful removal from a missing statement.

The binary COM_STMT_CLOSE path already performs an explicit GetPrepareStmt check before deallocation, so textual and binary prepared-statement cleanup currently have different missing-name behavior.

Activity

  1. added this to the MO-202607 milestone on Jul 21, 2026
  2. added
    kind/bug
    on Jul 21, 2026
  3. added theissue type on Jul 21, 2026
  4. Ariznawlll commented on Jul 22, 2026

    @Ariznawlll
    CollaboratorAuthor

    最新 main 回归结果(2026-07-22)

    • 测试基线:c0486a2446c84c6dd6bf142494fe85243877ddc5
    • 执行不存在名称的 DEALLOCATE PREPARE。
    • 实际结果:仍静默成功,后续 SQL 正常继续。
    • 结论:问题仍可复现。
  5. added
    severity/s0
    and removed on Jul 28, 2026
  6. added a commit that references this issue on Jul 28, 2026
    071f8e4
  7. Ariznawlll commented on Jul 30, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main(截至 2026-07-30 16:30,Asia/Shanghai)
    • commit:41332062a6740978f269088a92ee362a888c7bd7
    • 部署方式:从该官方 commit 源码构建;etc/launch-with-proxy/launch.toml(2 CN + 1 TN + Proxy),SQL 入口 127.0.0.1:6001
    • 测试日期:2026-07-30

    原问题验证

    直接 DEALLOCATE PREPARE does_not_exist 和对同一 statement 二次 DEALLOCATE 均返回 unknown prepared statement 错误;完整黑盒 3/3 通过。

    Happy Path 覆盖

    1. 正常 PREPARE、带参数 EXECUTE 得到 5,首次 DEALLOCATE 成功。
    2. 报错之后 SELECT 1/2 均正常,连接未被破坏。

    Unhappy Path 覆盖

    1. 从未创建过的 statement 名称被拒绝。
    2. 已经释放的 statement 再次释放被拒绝。
    3. 两类失败后会话继续可用,未误删其他 prepared statement。

    白盒验证

    TestRemovePrepareStmt 连续 3 轮通过。

    回归测试

    修复提交 071f8e4ba 已加入 test/distributed/cases/prepare/deallocate_unknown.sql。

    测试证据

    完整 3 轮 SQL 结果、测试脚本、Proxy 黑盒日志、定向 UT 与 -race 输出:https://gist.github.com/Ariznawlll/b8f1a22642a58fd5264482687534728b

    测试结论

    测试通过。

  8. Ariznawlll commented on Jul 30, 2026

    @Ariznawlll
    CollaboratorAuthor

    motr 黑盒回归已补充

    • PR:matrixorigin/motr#72
    • 用例:suites/14_issue_regression/t/issue_25978_deallocate_unknown.test
    • 覆盖:未知及重复 DEALLOCATE 返回 1243,正常 PREPARE 生命周期和后续 SQL 可继续执行
    • 本地验证:基于 MatrixOne main@41332062a6740978f269088a92ee362a888c7bd7,该批 14 个用例连续 3 轮为 42/42 成功(504/504 语句);完整 14_issue_regression suite 为 124 成功、0 失败。
  9. added 3 commits that reference this issue on Sep 17, 2026
    025259d
    15be044
    85b44b6
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