Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Branch Name
main
Commit ID
Other Environment Information
- Hardware parameters: Apple Silicon local environment
- OS type: macOS
- Others: MatrixOne 1 LOG / 1 TN / 2 CN / Proxy; MySQL Connector/J 8.3.0; server-side prepared statements enabled
Actual Behavior
A server-side prepared SELECT * retains the result metadata captured when the table had two columns. After another connection executes ALTER TABLE ... ADD COLUMN, reusing the same PreparedStatement returns a three-column result description without refreshing the prepared column definition.
Connector/J then accesses the third field through a two-entry cached definition and raises:
java.sql.SQLException: java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2
Caused by: java.lang.ArrayIndexOutOfBoundsException
at com.mysql.cj.protocol.a.MergingColumnDefinitionFactory.createFromFields(...)
at com.mysql.cj.jdbc.ServerPreparedStatement.executeInternal(...)
The behavior occurs when the DDL is executed on the same CN, another CN, and through a Proxy connection. A client-side prepared-statement control refreshes the result correctly.
Expected Behavior
Executing the existing server-side PreparedStatement after the table metadata changes should reprepare or otherwise return a column definition consistent with the result set. For the example below, the reused SELECT * should expose three columns and must not cause a Connector/J runtime exception.
Steps to Reproduce
String url = "jdbc:mysql://127.0.0.1:6001/db"
+ "?useServerPrepStmts=true&cachePrepStmts=true";
try (Connection query = DriverManager.getConnection(url, user, password);
Connection ddl = DriverManager.getConnection(url, user, password);
Statement change = ddl.createStatement();
PreparedStatement ps = query.prepareStatement(
"select * from jdbc_prepared_ddl where id=?")) {
change.execute("create table jdbc_prepared_ddl(id int primary key, v varchar(32))");
change.executeUpdate("insert into jdbc_prepared_ddl values(1,'initial')");
ps.setInt(1, 1);
try (ResultSet rs = ps.executeQuery()) {
rs.next();
assert rs.getMetaData().getColumnCount() == 2;
}
change.execute("alter table jdbc_prepared_ddl add column extra int default 7");
ps.setInt(1, 1);
try (ResultSet rs = ps.executeQuery()) { // Connector/J throws here
rs.next();
assert rs.getMetaData().getColumnCount() == 3;
}
}Additional information
- Same-CN path: reproduced 3/3.
- Cross-CN DDL invalidation path: reproduced 3/3.
- Proxy query path with DDL on a CN: reproduced 3/3.
useServerPrepStmts=falsecontrol: the same lifecycle completed correctly 3/3, including add/drop column, view recreation, rename/rename-back, and table drop/recreate.- Related Java/JDBC release-gate tracking: [TestCase]: Java + MyBatis+MO framework scenario testing #26623.
Activity
Ariznawlll commentedon Sep 21, 2026
补充结果形状变更矩阵(同一固定提交
57c280ed48fdccec3c2eb25042820deaf1eca3c1):ArrayIndexOutOfBoundsException不只发生在ALTER TABLE ADD COLUMN。以下两种生命周期也会让既有的 server-sidePreparedStatement保留较短的旧列定义,随后接收更多的新列:SELECT *在两列表上 prepare;随后 drop/recreate 同名表为三列;复用原 statement 时 Connector/J 报Index 2 out of bounds for length 2。SELECT *在两列 view 上 prepare;随后 drop/recreate 同名 view 为三列;复用原 statement 时出现相同异常。上述两种情况在以下路径各重复 3 次,现象一致:
问题边界目前比较明确:
INT → VARCHAR类型修改、列顺序调整均能在原 server-side statement 上刷新为新元数据和新值;useServerPrepStmts=false下,add/drop column、rename、类型修改、列重排、表和 view 重建都返回正确的新列定义。因此当前证据指向 server prepared 结果元数据在“列数增加”时没有完成兼容的 reprepare/refresh,而不是通用 DDL 可见性问题。
aptend commentedon Sep 29, 2026
I reproduced all three reported two-column → three-column cases—adding a column, recreating the table, and recreating the view—using Connector/J 8.3.0 against MySQL 8.4.11. All three produce the same
ArrayIndexOutOfBoundsException; all three pass withuseServerPrepStmts=false.MySQL bug #97924 records the same behavior. MySQL verified it and ultimately classified it as “Not a Bug”, explaining that Connector/J retains prepared result metadata across schema changes.
This confirms the reported failure, but does not indicate a MatrixOne-specific defect. I suggest treating #29180 as a Connector/J compatibility limitation.
Ariznawlll commentedon Oct 2, 2026
测试版本
main@d50a2d475a406829f67127fef7b2ad4abc1c1d3dAriznawlll/mo-test-reports@733aa7cdbec7c0043236d9d230933503efbb4a96原问题验证
研发已使用 Connector/J 8.3.0 对 MatrixOne 和 MySQL 8.4.11 进行相同对照:复用已执行过的 server-side prepared
SELECT *,随后通过另一连接 ADD COLUMN、重建表或重建 view,三类场景都会因 Connector/J 保留旧结果元数据而触发ArrayIndexOutOfBoundsException。MySQL 对应 Bug #97924 也被判定为Not a Bug,因此该现象不是 MatrixOne 特有的服务端缺陷。Happy Path 覆盖
useServerPrepStmts=false的 client-side prepared control 在上述 DDL 生命周期中可以重新读取列定义;Unhappy Path 覆盖
白盒验证
本条没有 MatrixOne 修复 PR。研发结论指向 Connector/J 对 prepared result metadata 的缓存行为,并由 MySQL 8.4.11 对照确认。对应产品边界已写入兼容性文档
JDBC-001。回归测试
该场景依赖特定 Connector/J 版本,并且“旧 handle 在 DDL 后抛异常”是已接受的客户端限制,不应作为预期失败固化到 MOTR;否则驱动未来修复后反而会造成回归误报。文档记录了推荐替代方案和仍需作为 bug 处理的边界。
测试证据
测试结论
测试通过。