Repository navigation
Description
Description
PREPARE / EXECUTE of EXPLAIN ANALYZE returns internal error: invalid bytes based slice on current main. With the client instructed to continue after the first error, the same session then receives a second internal error and is disconnected. This is not tied to MATCH, vector indexes, or parameter binding: the smallest reproduction is a literal predicate over an ordinary two-column table.
Environment
- Branch:
main - Commit:
59517279b80b9e260feebb41f2a5105da5941b50 - Deployment: locally built two-CN MatrixOne instance; reproduction executed through the MySQL text protocol against one CN.
- Date: 2026-08-03
Steps to reproduce
CREATE DATABASE IF NOT EXISTS prepared_explain_analyze_repro;
USE prepared_explain_analyze_repro;
CREATE TABLE t (
id INT PRIMARY KEY,
v INT NOT NULL
);
INSERT INTO t VALUES (1, 7), (2, 8), (3, 7);
PREPARE p FROM
'EXPLAIN ANALYZE SELECT id FROM t WHERE v = 7 ORDER BY id';
EXECUTE p;
DEALLOCATE PREPARE p;The parameterized form fails identically:
PREPARE p FROM
'EXPLAIN ANALYZE SELECT id FROM t WHERE v = ? ORDER BY id';
SET @v = 7;
EXECUTE p USING @v;Actual behavior
EXECUTE returns:
ERROR 1105 (HY000): internal error: invalid bytes based slice
When the client continues in the same session, a following SELECT returns a second internal error: invalid bytes based slice, and the next statement reports Lost connection to MySQL server during query.
The literal and parameterized minimal reproducers each failed 3/3 times. The CN process remained available: a new connection could execute SELECT 1 and an independent indexed fulltext query after every failed run.
Expected behavior
EXECUTE should return the single text column containing the EXPLAIN ANALYZE output, as direct EXPLAIN ANALYZE does. An execution error must not corrupt the session protocol state or disconnect the client.
Stability and controls
- Literal prepared
EXPLAIN ANALYZE: fails 3/3. - Parameterized prepared
EXPLAIN ANALYZE: fails 3/3. - Direct
EXPLAIN ANALYZE SELECT ...: succeeds 3/3 and returns the expected plan text. - Prepared ordinary
SELECT ... WHERE v = ?: succeeds 3/3 and returns1,3. - Prepared
EXPLAINwithoutANALYZE, including a parameterized fulltext query: succeeds 3/3. - Post-failure new-session health and indexed-query controls: succeed after every failing run.
Evidence
The minimal scripts and the three raw client outputs for each branch are preserved in the test artifacts as prepared-explain-analyze-literal.sql, prepared-explain-normal-param.sql, prepared-explain-ft-param-explain.sql, and prepared-explain-analyze-session-state.sql.
Code analysis
The behavior is consistent with a result-metadata mismatch in pkg/frontend/result_row_stmt.go. getPreparedResultColumns special-cases only *tree.ExplainStmt and declares one varchar result column, but does not handle *tree.ExplainAnalyze (lines 54-66 at the tested commit). The direct ExplainAnalyze execution path constructs an explain-text result. The observed invalid bytes based slice is raised while serializing a value through the bytes-oriented result path (pkg/frontend/output.go:672). This is a code-level hypothesis; the SQL reproduction above is independent of this analysis.
Regression coverage
Add deterministic frontend/SQL coverage for both literal and parameterized PREPARE ... FROM 'EXPLAIN ANALYZE SELECT ...', asserting one text result column, successful execution, and a usable same session afterwards. The existing prepared-EXPLAIN coverage introduced by #26046 appears to cover EXPLAIN but not EXPLAIN ANALYZE.
Related
- [Bug]: PREPARE of EXPLAIN SELECT returns an internal error #25991 / fix(frontend): support prepared EXPLAIN statements #26046 fixed prepared
EXPLAIN SELECT; this issue is the uncoveredPREPARE EXPLAIN ANALYZEform. - [Tech Request]: support explain analyze for executing prepared statement #13885 requested
EXPLAIN ANALYZE EXECUTE <prepared-statement>, which is a different SQL shape.
Activity
fix(frontend): preserve prepared EXPLAIN result metadata (#26620)
Ariznawlll commentedon Aug 4, 2026
测试版本
mainc726a6199094184a2e6ebc7504c3e011982b8976原问题验证
创建
t(id int primary key, v int)并写入(1,7),(2,8),(3,7)后,直接执行EXPLAIN ANALYZE SELECT id FROM t WHERE v=7 ORDER BY id可返回单列文本计划;但执行:在 3 个新连接中均返回
ERROR 1105 (HY000): internal error: invalid bytes based slice。这正是 issue 原始 SQL-level PREPARE/EXECUTE 路径。Happy Path 覆盖
EXPLAIN ANALYZE连续执行 3 次均返回一个非空文本计划列。SELECT id FROM t WHERE v=? ORDER BY id连续执行 3 次,每次均返回1,3;因此不是基本 COM_STMT_PREPARE/EXECUTE 不可用。explain、explain analyze、explain phyplan元数据以及 rebuild 场景均通过。Unhappy Path 覆盖
EXPLAIN ANALYZE:3/3 为invalid bytes based slice。EXPLAIN ANALYZE ... v=?:3/3 为同一错误。PrepareContext("EXPLAIN ANALYZE ..."):3/3 在 prepare 阶段报ERROR 1064,错误位置稳定在第二个EXPLAIN ANALYZE前;普通 binary prepared SELECT 对照正常。busy buffer / commands out of sync,后续协议变体使用新连接独立验证,避免把连接污染误判为其他变体结果。白盒验证
163a769a845548c0ea2549700f6999e1a4410b07是当前 main 的祖先。getPreparedResultColumnsFromPlan已为ExplainStmt、ExplainAnalyze、ExplainPhyPlan构造 VARCHAR 结果列;对应 focused UT 通过。这说明需要继续追踪 live SQL/COM_STMT 执行与单测构造的 metadata/response 路径差异;本轮不把该差异臆测为单一根因。
回归测试
当前产品路径失败,未提交会掩盖失败的回归用例。修复后应在 prepared/protocol scenario 中加入 literal、marker、binary COM_STMT_PREPARE/EXECUTE、同连接重复执行,以及失败后连接可继续使用的断言;该场景适合
motr/suites/14_issue_regression。测试证据
前两条均失败,第三条通过;全部在上述 main commit 的同一隔离集群执行。
测试结论
测试不通过。
Ariznawlll commentedon Aug 4, 2026
本轮失败路径与回归处理
main@c726a6199094184a2e6ebc7504c3e011982b8976127.0.0.1:6001;2026-08-04。原复现仍为 3/3:SQL-level
PREPARE ... FROM 'EXPLAIN ANALYZE ...'的 literal 和带参数版本,在EXECUTE时均报invalid bytes based slice。普通 preparedEXPLAIN SELECT作为控制路径可运行,说明不是连接或通用 PREPARE 失败。因此该失败没有写入 motr#74 的
.result:把当前 product failure 录成预期输出会掩盖缺陷。研发修复后应补一个14_issue_regressionSQL 用例,同时断言 literal/parameterizedEXPLAIN ANALYZE、重复执行和失败后 session 可继续执行。详细初始复现与日志见本 issue 先前测试评论。测试不通过。
Ariznawlll commentedon Aug 6, 2026
测试版本
main09e02eea38bfa87e4c4333ffb57b370091136bc8原问题验证
对
PREPARE ... FROM 'EXPLAIN ANALYZE SELECT ...'后的EXECUTE,以及WHERE v=?+EXECUTE ... USING @v,均可返回 ANALYZE plan。连续 3 轮执行 literal 和参数7 -> 8 -> 7均成功,且同一会话后select count(*)仍为3。Happy Path 覆盖
EXPLAIN ANALYZE。EXPLAIN ANALYZE,同一 handle 改变参数后复用。db.Prepare/stmt.Query连续执行7 -> 8 -> 7;每次都读取到包含Analyze:的 plan 行。Unhappy Path 覆盖
本 issue 是“内部结果字节切片”错误导致的正常语句失败;回归额外断言每次执行后连接仍可查询,覆盖原问题中的会话损坏风险。没有人为构造无效 SQL,因为那不覆盖该结果编码路径。
白盒验证
binary scenario 验证 COM_STMT_PREPARE/COM_STMT_EXECUTE,补足 SQL
PREPARE不能覆盖的协议分支。回归测试
suites/14_issue_regression/t/issue_26602_prepared_explain_analyze.testscript/14_issue_regression/issue_26602_prepared_explain_analyze_binary.sh、suites/scenarios/14_issue_regression/issue_26602_prepared_explain_analyze_binary.go测试结论
测试通过。
Ariznawlll commentedon Aug 7, 2026
测试版本
maind0057b3503611022cdf9a6e24c98065d209eb8e4原问题验证
创建
t(id int primary key, v int)并写入(1,7),(2,8),(3,7)后,以下 SQL 的EXECUTE已正常返回单列EXPLAIN ANALYZE文本:每轮计划文本均含
Analyze,未再出现invalid bytes based slice或随后同连接不可用的问题。Happy Path 覆盖
EXPLAIN ANALYZE SELECT ...:返回一个非空文本计划列。PREPARE/EXECUTE连续 3 轮均返回含Analyze的单列计划。7 → 8 → NULL → 7反复绑定,四次均返回含Analyze的计划。PrepareContext/QueryContext用7 → 8 → NULL → 7重复执行;每次结果元数据恰为 1 列,且计划文本含Analyze。select 1均成功。Unhappy Path 覆盖
EXPLAIN ANALYZE不提供USING参数,正确返回Incorrect arguments to EXECUTE。3,没有 DDL/DML 副作用。白盒验证
ExplainStmt、ExplainAnalyze、ExplainPhyPlan的 prepared-result 元数据子路径,以及 rebuild 的ExplainAnalyze子路径,连续 3 次通过。回归测试
当前源码中的 frontend focused UT 已覆盖元数据构造。本轮未新增 motr 用例;此前关联的 motr#81 当前为 Closed 且未合入,因此没有把未合入分支作为本轮回归依据。
测试证据
live 双 CN 验证命令:
测试结论
测试通过。
fix(frontend): preserve prepared EXPLAIN result metadata (matrixorigi…
fix(frontend): preserve prepared EXPLAIN result metadata (matrixorigi…
fix(frontend): preserve prepared EXPLAIN result metadata (matrixorigi…