Repository navigation
Description
Description
A valid two-column UNION ALL with a constant string in the right branch and an outer filter triggers a recovered internal vector/slice error. After the error, the same MySQL-protocol connection cannot execute a normal query: the next response has a wrong packet sequence number.
Environment
- Branch:
main - Commit:
5a5501b3e1048f3d19d96824cc68a62b7f0fcb07(fixed official-main checkout tested on 2026-10-12) - Deployment: local 1 LOG + 1 TN + 1 CN, PyMySQL client; MySQL 8.0.46 control
Steps to reproduce
On one connection, execute these two statements in order:
SELECT v FROM (SELECT 1 AS k, 'ten' AS v
UNION ALL SELECT 2, 'twenty') AS u
WHERE k > 0;
SELECT 1;Actual behavior
The first query returns 1105 internal error: invalid bytes based slice (or, with LENGTH(v)/GROUP_CONCAT(v), 20101 internal error: panic unsafe slice cast: from length 8 is not enough for length 24). The next SELECT 1 on the same connection fails in the client with Packet sequence number wrong - got 2 expected 1. A new connection can still execute SELECT 1, so the service stays available but the affected session is unusable.
Expected behavior
The valid first query returns ('ten'), ('twenty'); the second returns 1. If any statement fails, the protocol response must still allow a subsequent statement on the same connection, as it does after ordinary SQL errors.
Stability and controls
- Minimal query followed by
SELECT 1: 3/3 first-query errors and 3/3 same-connection packet-sequence failures with fresh connections per repetition. SELECT vwithout the outer filter, a one-column string UNION ALL, and the same two-column query with a table-backed right branch all return correct results.- An ordinary unknown-column error followed by
SELECT 1succeeds on the same connection 3/3; a fresh connection after this internal error also succeeds. - MySQL 8.0.46 returns the two expected string rows and keeps the connection usable.
Evidence and code analysis
At this SHA, EXPLAIN VERBOSE shows the UNION ALL left output as ten but the right Project output as integer 2 instead of twenty. The recovered unsafe-slice stack begins in pkg/common/util/unsafe.go:89; the remapping path is in pkg/sql/plan/query_builder.go around the set-operation branch. The wrong positional mapping likely causes a type-incompatible physical vector; the exact ownership of the protocol desynchronization still needs investigation.
Regression coverage
Cover direct and server-prepared string projections, normal controls, and a follow-up query on the same connection after the error. Assert process availability and clean response sequencing.
Related
#30007 tracks silent wrong numeric results and persisted values from a nearby positional-remapping path; #29989 tracks the explicit projection-width error. This issue tracks the distinct vector error plus connection-state failure.
Activity
Ariznawlll commentedon Oct 12, 2026
现象:Prepared 查询报错后,同一连接无法继续使用
测试版本:
main/5a5501b3e1048f3d19d96824cc68a62b7f0fcb07。在同一连接依次执行:PREPAREEXECUTE1105 internal error: invalid bytes based sliceten、twentySELECT 1(同一连接)Packet sequence number wrong - got 2 expected 11使用全新连接重复 3 次,结果一致。这里验证的是 SQL
PREPARE/EXECUTE,尚未验证驱动层COM_STMT_PREPARE。Ariznawlll commentedon Oct 12, 2026
补充定位与修复(PR #30015):
新增 SQL 回归覆盖直接查询、SQL PREPARE 复用及同连接后续查询;本地新用例重复 3 次均得到正确结果。协议单测覆盖文本和二进制 prepared 两条路径,完整 frontend 单测已通过。PR 的 GitHub CI 仍在运行。
fix(sql): preserve filtered UNION ALL right branch columns (#30015)
Ariznawlll commentedon Oct 13, 2026
测试版本
main;commit:175a645a85994f2c95992d3aa8d6dacb6d9e167f;2026-10-13。原问题验证
字符串 UNION ALL 过滤投影的直接查询返回 ten、twenty;SQL PREPARE 在参数 0→1→0 复用时分别返回两行、一行、两行,同一连接随后的 SELECT 1 均为 1。 对应定向用例在 MOTR 入口重复执行 3 次均通过(每次脚本内再执行 3 轮)。
Happy Path 覆盖
未过滤 UNION 对照与过滤查询一致,结果不再出现整数向量误当字符串。
Unhappy Path 覆盖
先前会导致内部编码错误及下一条命令包序号错乱;本次每次复用后同连接可继续查询。
白盒验证
本次以真实 SQL/协议行为直接判定;没有把仅凭源码推断当作运行结果。
回归测试
MOTR PR #234 中的 sql_composition_contracts.py 已提交;离线 CI 通过,仍待正常 review/merge。该缺陷由确定性语义/类型/协议边界触发,不需要另加 big-data 或 chaos 才能验收。
测试证据
PR 验证记录及 CI 运行。
测试结论
测试通过。
fix: preserve set-operation columns through remapping (#30028)