Skip to content

[Bug]: PREPARE of EXPLAIN SELECT returns an internal error #25991

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues.

The existing #22765, #15389, #13885, and #14533 cover explaining an already prepared statement through EXPLAIN ... EXECUTE. This issue covers a different SQL shape: preparing an EXPLAIN SELECT statement itself.

Branch Name

main

Commit ID

c0486a2446c84c6dd6bf142494fe85243877ddc5

Other Environment Information

  • MatrixOne: 8.0.30-MatrixOne-v1.3.0
  • MySQL comparison: 8.0.45
  • SQL-level PREPARE / EXECUTE through the mysql client

Actual Behavior

MatrixOne returns an internal error while preparing an EXPLAIN SELECT, even when the statement has no parameter markers:

ERROR 20101 (HY000): internal error: statement: 'explain select * from src where id >= 2'

The parameterized form returns the same internal error:

ERROR 20101 (HY000): internal error: statement: 'explain select * from src where id >= ?'

Direct EXPLAIN SELECT ... works, and MySQL 8.0.45 supports both prepared forms. The MatrixOne result reproduced 3/3 times for both literal and parameterized forms.

Expected Behavior

PREPARE should accept EXPLAIN SELECT, and EXECUTE should return the explain result, consistent with MySQL. At minimum, this path should not return an internal error.

Steps to Reproduce

DROP DATABASE IF EXISTS ps_explain;
CREATE DATABASE ps_explain;
USE ps_explain;
CREATE TABLE src(id INT PRIMARY KEY, n INT);
INSERT INTO src VALUES (1,10),(2,20),(3,30);

-- Direct control works.
EXPLAIN SELECT * FROM src WHERE id >= 2;

-- Literal prepared EXPLAIN fails at PREPARE in MatrixOne.
PREPARE pe0 FROM 'EXPLAIN SELECT * FROM src WHERE id >= 2';
EXECUTE pe0;
DEALLOCATE PREPARE pe0;

-- Parameterized prepared EXPLAIN also fails at PREPARE.
PREPARE pe1 FROM 'EXPLAIN SELECT * FROM src WHERE id >= ?';
SET @id = 2;
EXECUTE pe1 USING @id;
DEALLOCATE PREPARE pe1;

Additional Information

The plan builder handles ExplainAnalyze and ExplainPhyPlan, but the normal ExplainStmt does not have a corresponding branch in the generic prepared-statement planning path. It falls through to the default internal-error branch in pkg/sql/plan/build.go.

Activity

  1. added this to the MO-202607 milestone on Jul 22, 2026
  2. added
    kind/bug
    on Jul 22, 2026
  3. added theissue type on Jul 22, 2026
  4. self-assigned this
    on Jul 22, 2026
  5. added
    severity/s0
    and removed on Jul 22, 2026
  6. LeftHandCold commented on Jul 23, 2026

    @LeftHandCold
    Collaborator

    fixed

  7. Ariznawlll commented on Jul 23, 2026

    @Ariznawlll
    CollaboratorAuthor

    最新 main 验证结果:通过

    测试版本:MatrixOne main@ebd05ba52f0d08afb4225e7b4b2e97e8030c057d

    测试步骤

    1. 执行字面量形式的 PREPARE ... FROM 'EXPLAIN SELECT ...'。
    2. 执行带参数占位符的 PREPARE ... FROM 'EXPLAIN SELECT ... WHERE ... = ?'。
    3. 设置参数后执行 prepared statement,并执行 DEALLOCATE PREPARE。

    实际结果

    • 两种 EXPLAIN SELECT 均可成功 PREPARE。
    • 带参数的 prepared statement 可正常执行。
    • 未出现语法错误、prepare 失败或异常退出。
    • 手工连续执行 3 轮通过;motr 回归连续执行 10 轮通过。

    回归用例

    • motr PR #61
    • 14_issue_regression.issue_25991_prepare_explain
    • motr commit:5c7c1e5bbfa9f5f03c339a34fb931a4a2e2a946d

    结论:原问题在最新 main 上未再复现。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions