Repository navigation
Description
Description
When Connector/J uses a real server-side prepared statement (useServerPrepStmts=true), overloaded numeric functions are bound to an integer overload before the value type from COM_STMT_EXECUTE is available. Valid floating-point/decimal parameters are then rejected. This affects at least sleep(?) and abs(?).
The equivalent SQL literal, Connector/J client-side prepared statement, and server-side prepared statement with an explicit CAST(? AS DOUBLE) all succeed.
Environment
- Branch:
main - Commit:
99d03a52f78b9b42243c169e6d554fafd32f73c4 - Deployment: local standalone launch, SQL port 26001
- Client: MySQL Connector/J 8.0.33 and 8.0.15
- Date: 2026-08-18
Steps to reproduce
Connect with:
jdbc:mysql://127.0.0.1:26001/?useServerPrepStmts=true&useSSL=false&serverTimezone=UTC
Then execute:
try (PreparedStatement ps = conn.prepareStatement("select sleep(?)")) {
System.out.println(ps.getClass().getSimpleName()); // ServerPreparedStatement
ps.setDouble(1, 0.05d);
ps.executeQuery();
}
try (PreparedStatement ps = conn.prepareStatement("select abs(?)")) {
ps.setDouble(1, -1.5d);
ps.executeQuery();
}Controls:
select sleep(0.05); -- succeeds and returns 0
select abs(-1.5); -- succeeds and returns 1.5The following JDBC controls also succeed:
// useServerPrepStmts=false
prepareStatement("select sleep(?)").setDouble(1, 0.05d);
// useServerPrepStmts=true
prepareStatement("select sleep(cast(? as double))").setDouble(1, 0.05d);
prepareStatement("select abs(cast(? as double))").setDouble(1, -1.5d);Actual behavior
sleep(?) with setDouble, setFloat, setBigDecimal, or setString("0.05") fails:
SQLState=HY000 errorCode=20203
invalid argument cast to uint64, bad value 0.05
abs(?) with setDouble(-1.5) or setBigDecimal(-1.5) fails:
SQLState=HY000 errorCode=20203
invalid argument cast to int, bad value -1.5
Expected behavior
The server-side prepared forms should select or rebind the overload using the bound parameter's numeric type and produce the same result as the literal/client-prepared controls:
sleep(0.05)returns0after approximately 50 ms.abs(-1.5)returns1.5.
Stability and controls
- Reproducer: 3/3 on the listed latest official
maincommit; identical result with Connector/J 8.0.33 and 8.0.15. - Normal controls: SQL literals, client-side Prepare, integer server-side Prepare, and explicit
CAST(? AS DOUBLE)all pass. - Scope check: reproduced with two separate overloaded functions (
sleepandabs), so this is not specific to sleep timing. - Post-failure state: the same connection and the same prepared statement remain reusable after rebinding an integer value; no connection corruption was observed.
- Failure atomicity/data check: not applicable; the minimal reproducer is read-only.
Evidence
Fresh 3-round verification on 99d03a52f78b9b42243c169e6d554fafd32f73c4 produced the same matrix in every round:
PASS literal sql=select sleep(0.05) value=0
PASS client-double implementation=ClientPreparedStatement value=0
PASS server-int implementation=ServerPreparedStatement value=0
FAIL server-double implementation=ServerPreparedStatement state=HY000 code=20203 message=invalid argument cast to uint64, bad value 0.05
FAIL server-decimal implementation=ServerPreparedStatement state=HY000 code=20203 message=invalid argument cast to uint64, bad value 0.05
PASS server-cast-double implementation=ServerPreparedStatement value=0
PASS server-rebind int-double-int connection-and-statement-reusable
PASS literal sql=select abs(-1.5) value=1.5
FAIL abs-server-double implementation=ServerPreparedStatement state=HY000 code=20203 message=invalid argument cast to int, bad value -1.5
PASS abs-server-cast-double implementation=ServerPreparedStatement value=1.5
The public source commit used for verification is 99d03a52.
Code analysis
Confirmed observations:
baseBindParaminitially represents a prepared parameter asT_text.sleephas bothuint64andfloat64overloads, with the integer overload listed first.ParseExecuteDatareads the binary protocol parameter type/value, but stores every value into a string vector.ResetParamRefRulepreserves the prepared expression's existing type when replacing the parameter value and only directly rebinds a function when one of its immediate arguments is aParamRef.
Hypothesis: the initial T_text parameter makes fixedTypeMatch choose the first/lowest-cost integer overload and insert an implicit cast. That cast wraps the ParamRef, so execute-time replacement does not rebind the outer overloaded function using the actual COM_STMT_EXECUTE numeric type. The bound decimal value is consequently forced through the previously selected integer cast.
Regression coverage
Add a protocol/integration regression using a real COM_STMT_PREPARE + COM_STMT_EXECUTE path (not SQL PREPARE/EXECUTE text commands):
sleep(?)with integer, float/double, decimal and string representations.abs(?)with negative integer, double and decimal values.- Rebind one statement across integer → double/decimal → integer.
- Assert literal and explicit-cast controls, exact values, error recovery, and statement/connection reuse.
Related
- JDBC/MyBatis exploration tracking: [TestCase]: Java + MyBatis+MO framework scenario testing #26623
- Prepared query timeout support tested through
sleep(?): [Bug]: max_execution_time is accepted but not enforced, breaking ODBC query timeout #26678 (non-duplicate; that case binds integer2) - Duplicate search covered open and closed issues using the exact errors,
sleep(?),useServerPrepStmts,ServerPreparedStatement,COM_STMT_EXECUTE, overload/function-type binding, and parameter-marker synonyms; no matching issue or linked fix PR was found.
Activity
Ariznawlll commentedon Aug 23, 2026
已在最新 main(cdf7888344df65136f6d0c9c35ead4940d69a793)验证修复。
验证内容:
已补充 MOTR 回归:matrixorigin/motr#117(issue_27294_prepared_numeric_overloads),使用真实 COM_STMT_PREPARE/COM_STMT_EXECUTE 覆盖 sleep/abs 的浮点与数字文本绑定及重用;PR 内 7 个场景连续 3 轮共 21/21 通过。
Ariznawlll commentedon Aug 24, 2026
测试版本
main53f6aa6f0bbdc59f924072e823cdcd48ff43a981原问题验证
该 issue 曾在较早的
maincommitcdf7888344df65136f6d0c9c35ead4940d69a793上关闭。当前 nightly 在更新后的main上重新执行同一 binary-protocol regression,COM_STMT_EXECUTE绑定小数参数0.01到SLEEP(?)仍失败:文本 SQL/显式
CAST(? AS DOUBLE)可工作,但 server-side prepared statement 仍把实际小数参数走整数转换。这是 prepared overload 重新绑定/类型处理仍未修复,不能通过修改 MOTR result 掩盖。Happy Path 覆盖
本次回归覆盖的正常控制为文本 SQL 与显式 DOUBLE CAST;失败后连接和测试进程没有出现 panic、重启或中断。
Unhappy Path 覆盖
不适用:本次验证为只读的参数类型兼容性校验。
白盒验证
不适用:该结论来自真实 binary protocol 回归执行,当前需要研发定位 overload 选择与 execute-time 参数类型重绑定路径。
回归测试
MOTR:
14_issue_regression.issue_27294_prepared_numeric_overloads,已在本次 nightly 执行。测试证据
ab9194eaaa4a2abbd683fcab5646bed3569e6c62测试结论
测试不通过。
fix: accept fractional prepared numeric overloads (#27556)
fix(frontend): reuse prepared runtime specialization (#27893)
Ariznawlll commentedon Sep 7, 2026
测试版本
mainbcd5ed833b5400fe95f322e4028adb2bde3de0a46001原问题验证
sleep(?)的整数、浮点和数值字符串绑定。abs(?)prepared handle,在整数和小数参数之间切换,核对返回类型和值。Happy Path 覆盖
sleep(?)正确接受整数、浮点和 numeric-text 绑定并返回预期结果。abs(?)在整数/小数重用时重新选择正确重载,数值不被截断。Unhappy Path 覆盖
白盒验证
不适用。本轮验证真实 binary protocol prepared 行为,未使用内部故障注入。
回归测试
已纳入 MOTR PR #145:
script/14_issue_regression/issue_27294_prepared_numeric_overloads.sh及对应 scenario。测试证据
测试结论
测试通过。
fix: accept fractional prepared numeric overloads (matrixorigin#27556)
fix(frontend): reuse prepared runtime specialization (matrixorigin#27893
fix: accept fractional prepared numeric overloads (matrixorigin#27556)
fix(frontend): reuse prepared runtime specialization (matrixorigin#27893
fix: accept fractional prepared numeric overloads (matrixorigin#27556)
fix(frontend): reuse prepared runtime specialization (matrixorigin#27893
fix: restore prepared TPCC filter selectivity with per-binding proof (#…