Repository navigation
Description
Description
When a result row cannot be serialized, the MySQL protocol layer sends an ERR packet inside writeResultSetRow2 and still returns the error. The statement handler then sends another ERR packet. The extra response is read as part of the next command, causing a packet-sequence error on the same connection. This remains a separate protocol defect even when the query-planner defect in #30010 is fixed.
Reproduction
On main commit 5a5501b3e1048f3d19d96824cc68a62b7f0fcb07, run both statements on one PyMySQL connection:
SELECT v FROM (
SELECT 1 AS k, 'ten' AS v
UNION ALL SELECT 2, 'twenty'
) AS u WHERE k > 0;
SELECT 1;The first statement produces 1105 internal error: invalid bytes based slice; the following SELECT 1 fails with Packet sequence number wrong - got 2 expected 1. Reproduced 3/3 on clean connections. Ordinary SQL errors do not poison the connection. #30010 contains the query-planner aspect and its controls.
The protocol mechanism was independently isolated with a focused unit fixture: a VAR_STRING result column paired with an int64 vector deliberately triggers the row encoder error. In both text-query and binary-prepared modes, WriteResultSetRow2 already emits an ERR packet before returning the error. The fixture fails in both modes, 3/3 runs, on the #30010 fix branch. The relevant frontend source files are byte-identical to official main d865e549cd743aa6d74d68b57212ee9d43169204 (2026-10-12). A fresh build of that exact main checkout was not completed because local compile space ran short; the branch-based focused test is the direct verification.
Expected
The row writer returns the serialization error without writing its own terminal ERR packet. The statement handler sends exactly one error response, and the next command on the same connection receives a correctly sequenced response.
Code path
pkg/frontend/mysql_protocol.go: writeResultSetRow2 invokes sendErrPacket on row append failure and returns the same error. pkg/frontend/mysql_cmd_executor.go then converts the returned error to a general error response. The second packet persists into the next command.
Scope and related issues
This is independent of the invalid UNION ALL projection mapped in #30010 and #30007. #27338 concerns COM_STMT_CLOSE, a no-response command, and is a different protocol path. Regression coverage should include both COM_QUERY and COM_STMT_EXECUTE row-encoding failures and assert one terminal ERR packet per command.
Activity
Ariznawlll commentedon Oct 12, 2026
修复已提交到 #30015:结果行写入层不再提前发送 ERR 包,仅向语句处理层返回错误,由后者发送一次终止错误响应。新增文本查询与二进制 prepared 的定向单测,修复前两条路径均复现重复响应,修复后各重复 3 次通过;完整 frontend 单测已通过。GitHub CI 仍在运行。
fix(sql): preserve filtered UNION ALL right branch columns (#30015)
Ariznawlll commentedon Oct 13, 2026
测试版本
main175a645a85994f2c95992d3aa8d6dacb6d9e167f(修复 PR #30015 的 merge commit)原问题验证
原问题需要结果列的协议声明为字符串、实际向量为 int64 的内部类型不匹配。修复前行写入层先发送 ERR,再把错误交给语句处理层,造成重复终止包。当前 main 的定向单测以该精确注入分别覆盖
COM_QUERY和COM_STMT_EXECUTE:WriteResultSetRow2返回invalid bytes based slice,自身不发送任何包;语句处理层写入后恰有一个 ERR 包。执行go test ./pkg/frontend -run '^TestResultRowEncodingErrorEmitsOneTerminalPacket$' -count=3通过。Happy Path 覆盖
同一 main 上,相关
UNION ALL字符串投影及随后同连接SELECT 1正常;MOTR 的 SQL 组合回归连续 3 次通过。普通查询不会产生多余响应包。Unhappy Path 覆盖
对文本查询和二进制 prepared 两种协议模式注入行编码失败,各自断言错误向上传递、行写入层未提前发送 ERR、最终仅一个终止 ERR 包;资源清理与内存分配平衡也由单测检查。
白盒验证
定向 UT:mysql_protocol_row_error_test.go;本地
-count=3通过。该内部类型不匹配无法由修复后的正常 SQL 稳定构造,因此以白盒注入验证单包责任边界。回归测试
MatrixOne PR #30015 已合入上述 UT;关联 SQL/同连接控制见 MOTR #234。本 issue 的内部编码路径不添加无法真实触发的 MOTR 伪用例;不依赖数据量或故障注入,故不需要 big-data/chaos。
测试证据
ok github.com/matrixorigin/matrixone/pkg/frontend。测试结论
测试通过。