Repository navigation
Closed
Closed
Copy link
Description
Description
Connector/J 开启服务端游标读取(useCursorFetch=true)后,MatrixOne 在处理 COM_STMT_EXECUTE 时拒绝游标标志 1,查询无法执行,报错:
SQLState=HY000, errorCode=20301
invalid input: unsupported Prepare flag '1'
关闭 useCursorFetch 后,同一个 server-side prepared statement 查询正常返回结果。
Environment
- Branch:
main - Commit:
69abff30d1074f856a100e52e53be4127e5af8c2 - Build: source build, Go 1.26.5, darwin/arm64
- Deployment: 单进程本地 LOG/TN/CN,独立数据目录,CN SQL 端口
26001 - Java: JDK 20.0.1
- Drivers: MySQL Connector/J 8.0.15、8.0.33
Steps to reproduce
- 创建测试数据:
CREATE DATABASE jdbc_cursor_bug;
USE jdbc_cursor_bug;
CREATE TABLE cursor_rows(id INT PRIMARY KEY);
INSERT INTO cursor_rows VALUES (1),(2),(3),(4),(5);- 使用 Connector/J URL 参数:
useServerPrepStmts=true&useCursorFetch=true&defaultFetchSize=2
- 执行:
try (PreparedStatement ps = conn.prepareStatement(
"select id from cursor_rows order by id")) {
ps.setFetchSize(2);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
System.out.println(rs.getInt(1));
}
}
}Actual behavior
executeQuery() 直接失败,无法获得 ResultSet:
invalid input: unsupported Prepare flag '1'
Expected behavior
MatrixOne 应接受 Connector/J 发出的只读游标执行标志,并通过 MySQL server-side cursor / COM_STMT_FETCH 分批返回 5 行结果。
Stability and controls
- Connector/J 8.0.15 reproducer: 3/3 失败,错误完全一致
- Connector/J 8.0.33 reproducer: 3/3 失败,错误完全一致
- 8.0.15 control (
useCursorFetch=false): 3/3 通过,每次返回 5 行 - 8.0.33 control (
useCursorFetch=false): 3/3 通过,每次返回 5 行 - 每次失败后新连接仍能完成对照查询,无数据丢失或残留事务
- 测试库删除成功;服务进程仍在运行,未观察到 panic、hang 或重启
Evidence
Connector/J 8.0.15:
CURSOR_RUN_1=FAIL sqlState=HY000 code=20301 message=invalid input: unsupported Prepare flag '1'
CURSOR_RUN_2=FAIL sqlState=HY000 code=20301 message=invalid input: unsupported Prepare flag '1'
CURSOR_RUN_3=FAIL sqlState=HY000 code=20301 message=invalid input: unsupported Prepare flag '1'
CONTROL_RUN_1=PASS rows=5
CONTROL_RUN_2=PASS rows=5
CONTROL_RUN_3=PASS rows=5
CLEANUP=PASS
SUMMARY=cursorFailures:3/3,controls:3/3
Connector/J 8.0.33 得到相同的 3/3 失败和 3/3 对照通过结果。
Code analysis
pkg/frontend/mysql_protocol.go的parseStmtExecute在读取COM_STMT_EXECUTEflag 后,仅允许flag == 0;flag != 0直接返回unsupported Prepare flag。代码中的 TODO 也注明目前只支持CURSOR_TYPE_NO_CURSOR。pkg/frontend/mysql_protocol_predefines.go虽声明了COM_STMT_FETCH (0x1c),但命令执行分支没有对应处理路径。- 因此根因是 MatrixOne MySQL binary protocol 尚未实现 Connector/J server-side cursor 所需的
CURSOR_TYPE_READ_ONLY和后续 fetch 流程。
Regression coverage
建议修复时增加 motr/协议场景测试:使用 Connector/J 开启 useServerPrepStmts=true&useCursorFetch=true,设置正数 fetchSize,验证多批次读取、空结果、少于/等于/大于 fetch size、提前关闭 ResultSet,以及失败后的 statement/connection 可继续使用。
Related
- Java/MyBatis 场景测试跟踪:[TestCase]: Java + MyBatis+MO framework scenario testing #26623
- 未检索到包含
unsupported Prepare flag、useCursorFetch或COM_STMT_FETCH的同类 open/closed Issue 或修复 PR。
Metadata
Metadata
Assignees
Labels
kind/bugSomething isn't working
Activity
Ariznawlll commentedon Aug 24, 2026
测试版本
mainba8954d543af0bdfb1948a8b89f77f5235ac9259原问题验证
开启
useServerPrepStmts=true、useCursorFetch=true和defaultFetchSize=2,以 server prepared query 读取 5 行。连续 3 轮均成功返回[1,2,3,4,5],不再出现 Issue 中的 Prepare flag 拒绝。Happy Path 覆盖
fetchSize=2跨多页读取 5 行。[1,2,3,4,5]。Unhappy Path 覆盖
不适用:该问题的公开契约是只读游标执行。边界覆盖包含空结果和同一 statement 的重复读取;测试不修改数据,执行后表状态不变。
白盒验证
不适用:已通过真实 Connector/J 的 server cursor 协议路径完成验证。
回归测试
JdbcCompatibilityRegressionIT.java。JdbcCompatibilityRegressionIT连续执行 3 轮通过。测试证据
a6a562a1。测试结论
测试通过。
daviszhen commentedon Oct 16, 2026
v4.2.5 release-specific reproduction (arm64)
Independent replay on the official
matrixorigin/matrixone:latestimage — arm64/linux,VERSION()=8.0.30-MatrixOne-v4.2.5, single-node standalone, Apple M5 host, mysql 8.4 CLI. This comment does not assert anything about currentmain; it only records that the behaviour is still present in this release image.Still reproducible. Connector/J 8.0.33 against v4.2.5:
Because the failure happens when the statement is prepared, it affects any ORM/pool configuration that enables cursor fetching globally, rather than only large result sets.