You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Failed re-PREPARE keeps the previous statement instead of deallocating it #25977
When a prepared statement name is reused and the new PREPARE fails, MatrixOne keeps the previous statement under that name. A later EXECUTE therefore runs stale SQL.
MySQL deallocates the previous statement before attempting the new prepare; after the new prepare fails, no statement remains under that name.
Tested version
main at 3046f14d94b3f1a25839eeeb65729b64f85ac647.
Reproduction
Run the following in one session:
USE join_main_audit;
PREPARE s FROM'SELECT 1';
SET @bad ='SELECT * FROM prepare_missing_table';
PREPARE s FROM @bad;
EXECUTE s;
Actual result
The second PREPARE correctly reports that prepare_missing_table does not exist, but EXECUTE s still runs the old statement and returns:
1
This reproduces 3/3 times.
Expected result
The previous statement should be deallocated before the replacement is prepared. Since the replacement fails, EXECUTE s should report that the prepared statement does not exist.
MySQL 8.0.45 returns:
ERROR 1243 (HY000): Unknown prepared statement handler (s) given to EXECUTE
Root cause
The frontend builds the replacement object before calling Session.SetPrepareStmt. The old object is only closed inside SetPrepareStmt, so any parse, authorization, or planning error before that call leaves the old statement in ses.prepareStmts.
This also creates a stale-statement risk: a client may assume the failed replacement invalidated the old statement, while MatrixOne continues to execute the previous SQL.
每轮先 PREPARE stale FROM 'SELECT 1',再以相同名称执行失败 replacement。随后 EXECUTE stale 必须失败,而不是继续执行旧 SELECT 1;最后同名 PREPARE stale FROM 'SELECT 2' 与 EXECUTE 必须恢复成功。完整用例重复 3 次。
Activity
Ariznawlll commentedon Jul 22, 2026
最新 main 回归结果(2026-07-22)
c0486a2446c84c6dd6bf142494fe85243877ddc577的同名语句,再用语法错误 SQL 重新 PREPARE。EXECUTE仍返回旧值77。fix(frontend): deallocate stale statement before re-PREPARE (#26258)
Ariznawlll commentedon Aug 4, 2026
测试版本
mainc726a6199094184a2e6ebc7504c3e011982b8976原问题验证
每轮先
PREPARE stale FROM 'SELECT 1',再以相同名称执行失败 replacement。随后EXECUTE stale必须失败,而不是继续执行旧SELECT 1;最后同名PREPARE stale FROM 'SELECT 2'与 EXECUTE 必须恢复成功。完整用例重复 3 次。Happy Path 覆盖
2。Unhappy Path 覆盖
SELECT FROM语法错误:同样不会遗留可执行的旧句柄。白盒验证
本轮覆盖公共 statement-name 生命周期;未注入内部 registry 故障。关键断言是失败 re-PREPARE 后旧 name 不可执行,而非仅检查 replacement 返回 error。
回归测试
该稳定 SQL session 状态机适合 prepared BVT;若需要同一 socket 的 protocol handle 覆盖,可补
motr/suites/14_issue_regression。本轮未新提交。测试证据
三轮均通过。
测试结论
测试通过。
Ariznawlll commentedon Aug 4, 2026
motr 回归补充
main@c726a6199094184a2e6ebc7504c3e011982b8976127.0.0.1:6001;2026-08-04。3d79e01b6348e23bb747de5ab9a9d16995304a29。新增
suites/14_issue_regression/t/issue_25977_failed_reprepare_deallocates.test:PREPARE失败;随后执行旧名称均返回20400 invalid state prepared statement ... does not exist,证明旧 handle 已被释放、没有继续指向旧计划。2/3,验证失败不会把 session 或名称空间永久污染。执行证据:
该问题属于 SQL-level named PREPARE 生命周期,公开 SQL 已覆盖失败原子性与恢复,不额外采用白盒注入或 binary-protocol 场景。
fix(frontend): deallocate stale statement before re-PREPARE (matrixor…
fix(frontend): deallocate stale statement before re-PREPARE (matrixor…
fix(frontend): deallocate stale statement before re-PREPARE (matrixor…