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]: Prepared statements don't error on division by zero in strict mode #23438
kind/bugSomething isn't workingkind/compatibilityThe compatibility with mysql 8.0 should be discussed further.severity/s0Active / top priority for current sprint. Owner has committed to working on it now.
When using prepared statements (JDBC with useServerPrepStmts=true), INSERT/UPDATE with division by zero returns NULL instead of raising an error, even with STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO in sql_mode.
SET sql_mode ='STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO';
INSERT INTO t VALUES (1, 10/0);
-- Actual: Query OK (inserts NULL)
Expected Behavior
INSERT/UPDATE with division by zero should raise error when both STRICT_TRANS_TABLES and ERROR_FOR_DIVISION_BY_ZERO are enabled.
SET sql_mode ='STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO';
INSERT INTO t VALUES (1, 10/0);
-- Expected: ERROR 1365 (HY000): division by zero
Direct SQL execution works correctly; only prepared statements are affected.
Steps to Reproduce
Connect using JDBC with useServerPrepStmts=true
Execute:
CREATETABLEt (id INT, val INT);
SET sql_mode ='STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO';
INSERT INTO t VALUES (1, 10/0);
SELECT*FROM t;
INSERT succeeds with NULL instead of error
Root Cause
In PREPARE/EXECUTE phases, stmtType is "Prepare"/"Execute" not "Insert". checkDivisionByZeroBehavior() checks for "Insert"/"Update" stmtType, so it never triggers for prepared statements.
kind/bugSomething isn't workingkind/compatibilityThe compatibility with mysql 8.0 should be discussed further.severity/s0Active / top priority for current sprint. Owner has committed to working on it now.
Activity
daviszhen commentedon May 12, 2026
在最新的main 51df6a5 , 用 go和java的测试程序都未复现出来.
daviszhen commentedon May 12, 2026
java 测试程序.
23438.tar.gz
daviszhen commentedon May 12, 2026
分析有2点可能性.
1,
proc.Base.DivByZeroErrorMode的值有缓存性质. 如果同一个请求有多个语句时, 前一个语句的DivByZeroErrorMode会继承成给下一个条语句. 这个需要修改.2,
10/0, 被常量折叠. 代码了已经做了处理, 这种情况不折叠. 无需再修改.fix divByZero (#24355)
fix divByZero (matrixorigin#24355)
fix divByZero (matrixorigin#24355)
fix divByZero (matrixorigin#24355)