Repository navigation
Description
Description
A fresh, server-side prepared COALESCE(?, DECIMAL) query reports a string result type in PreparedStatement.getMetaData() before its first execution. The same handle returns a DECIMAL result type once executed. There is no DDL or statement-cache reuse. Clients that inspect prepared result metadata before binding/execution therefore receive the wrong type family.
Environment
- Branch: official
main, fixed test commit5a5501b3e1048f3d19d96824cc68a62b7f0fcb07(2026-10-12) - Deployment: isolated local MatrixOne, 2 CN / 1 TN / 1 LogService, direct CN at port 16001
- Control: independent MySQL 8.0.46; Connector/J 8.3.0 and 8.4.0,
useServerPrepStmts=true,emulateUnsupportedPstmts=false,cachePrepStmts=false
Steps to reproduce
Use a new JDBC connection and a fresh server-side PreparedStatement:
PreparedStatement ps = connection.prepareStatement(
"SELECT COALESCE(?,CAST(0 AS DECIMAL(20,6))) AS x");
System.out.println(ps.getMetaData().getColumnTypeName(1));
ps.setBigDecimal(1, new BigDecimal("1.25"));
ResultSet rs = ps.executeQuery();
System.out.println(rs.getMetaData().getColumnTypeName(1));The connection URL has useServerPrepStmts=true&emulateUnsupportedPstmts=false&cachePrepStmts=false. The handle class is ServerPreparedStatement on both servers.
Actual behavior
For every fresh handle, MatrixOne reports VARCHAR(65535,0):java.lang.String before execution, then DECIMAL(20,6):java.math.BigDecimal after execution. The value is 1.250000.
MySQL reports DECIMAL(65,30):java.math.BigDecimal both before and after execution. Its numeric value is 1.25 (displayed with scale 30). The report concerns the incorrect pre-execution type family, not the different DECIMAL precision/scale.
Expected behavior
The pre-execution result metadata should report a DECIMAL/numeric type, consistent with the query's numeric result and MySQL's server-side prepared metadata; it should not change from VARCHAR to DECIMAL merely because the first parameter is bound and executed.
Stability and controls
- Reproducer: 3/3 fresh handles with Connector/J 8.3.0 and 3/3 with 8.4.0.
- Control:
SELECT CAST(? AS DECIMAL(20,6)) AS xreportsDECIMAL(20,6):java.math.BigDecimalbefore and after execution on both MatrixOne and MySQL, 3/3 with each driver. - Execution values match numerically, and both connections remain usable. Failure atomicity is not applicable to this read-only metadata query.
- The MySQL compatibility contract's JDBC-001 exception concerns stale metadata on reused handles after DDL; this reproducer has no DDL and no reuse.
Evidence
The fixed-main exploratory probe and full output are saved locally under evidence/prepare_cross_20261012/PrepareCoalesceMetadataProbe.java and prepare-coalesce-metadata-8.3.log / prepare-coalesce-metadata-8.4.log. Representative output:
control run=0 preMO=DECIMAL(20,6):java.math.BigDecimal preMySQL=DECIMAL(20,6):java.math.BigDecimal
coalesce run=0 preMO=VARCHAR(65535,0):java.lang.String preMySQL=DECIMAL(65,30):java.math.BigDecimal postMO=DECIMAL(20,6):java.math.BigDecimal
Code analysis
The initial prepared result metadata is emitted before the execution-time parameter type is known. pkg/sql/plan/base_binder.go contains prepared-consumer binding for COALESCE, and pkg/frontend/mysql_cmd_executor.go handles binary PREPARE metadata. The exact point that chooses VARCHAR remains a hypothesis; no product source was modified.
Regression coverage
After a fix, add a binary-protocol JDBC/MOTR check for pre-execution and post-execution metadata on fresh and reused handles with DECIMAL, NULL and string bindings. This exploration did not add a formal regression case.
Related
- [TestCase]: Java + MyBatis+MO framework scenario testing #26623 tracks wider JDBC/ORM coverage.
- [Bug]: server prepared SELECT star keeps stale result metadata after ALTER ADD COLUMN #29180 is the separately documented Connector/J cache behavior on old
SELECT *handles after DDL; not this no-DDL case. - [Bug]: COALESCE widens bounded string branches to VARCHAR(65535) and BLOB #28897 concerns bounded string/binary
COALESCEtype inference and CTAS; not a prepared numeric result's pre-execution metadata.
Activity
Correct numeric COALESCE metadata during PREPARE (#30035)
Ariznawlll commentedon Oct 13, 2026
测试版本
main;commit:175a645a85994f2c95992d3aa8d6dacb6d9e167f;2026-10-13。原问题验证
真实 COM_STMT_PREPARE 对 COALESCE(?,DECIMAL(20,6)) 两种参数顺序均在执行前报告 DECIMAL 类型;首个 NULL 参数执行后仍报告 DECIMAL,连接继续可用。 对应定向用例在 MOTR 入口重复执行 3 次均通过(每次脚本内再执行 3 轮)。
Happy Path 覆盖
左右参数顺序与执行前后 metadata 一致。
Unhappy Path 覆盖
首个参数为 NULL 的二进制 COM_STMT_EXECUTE 不退化成 VARCHAR;语句关闭后下一条查询成功。
白盒验证
本次以真实 SQL/协议行为直接判定;没有把仅凭源码推断当作运行结果。
回归测试
MOTR PR #234 中的 issue_29964_29977_prepared_wire.py 已提交;离线 CI 通过,仍待正常 review/merge。该缺陷由确定性语义/类型/协议边界触发,不需要另加 big-data 或 chaos 才能验收。
测试证据
PR 验证记录及 CI 运行。
测试结论
测试通过。