Skip to content

[Bug]: prepared UNION filter loses a child projection column during remapping #29989

Closed

Description

@XuPeng-SH

Is there an existing issue for the same bug?

  • I have checked existing issues; exact error and prepared UNION/projection searches did not find a matching issue.

Branch Name

main

Commit ID

02a2823

Other Environment Information

Linux/amd64; Go 1.27.1; task-owned canonical embedded one-CN MatrixOne instance; MySQL protocol (go-sql-driver/mysql prepared statement). Three constant rows, no application schema required. The baseline checkout includes CI/test-only commits from PR #29978; its production sources are unchanged from the main SHA above.

Actual Behavior

Preparing the query succeeds. Executing it with parameter 0 returns SQL error 20101:

internal error: set operation child projection width mismatch after remap: left 2, right 1, output 2

Confirmed again on unchanged main production code. This reproduces without any window function. It also prevents prepared LAG/LEAD queries over the same UNION input from reaching window evaluation; that is a separate failure from #29925.

Expected Behavior

Execution with parameter 0 returns exactly (1,1), (2,1), (3,2) in that order. A valid prepared query must preserve the same set-operation output-column contract when filtering/pruning child projections.

Steps to Reproduce

Execute through a MySQL client with server-side prepared statements:

PREPARE q FROM 'select point,eid
from (select 1 point,1 eid,cast(1 as double) value
      union all select 2,1,2
      union all select 3,2,3) f
where point>? order by point';
SET @p=0;
EXECUTE q USING @p;
DEALLOCATE PREPARE q;

The directly executed verified API was database/sql.PrepareContext followed by stmt.QueryContext(ctx, 0); the SQL PREPARE spelling above expresses the equivalent request and has not separately been executed.

Additional information

Evidence: product-disposition-unmodified-base.log under the local task record /home/xupeng/.codex/issue-to-pr/matrixone/roi-20261012. The same fixture independently passes the reduced #29926 correlated SUM query. The earlier window-fix checkout also reproduced this exact plain-query failure, ruling out a window-only explanation. The failed statement leaves the service available. The width-consistency check detects a real planner mismatch; removing it or padding missing columns is not a fix. The first broken pruning/remapping owner still needs causal investigation.

Activity

  1. self-assigned this
    on Oct 12, 2026
  2. added
    kind/bug
    on Oct 12, 2026
  3. Ariznawlll commented on Oct 12, 2026

    @Ariznawlll
    Collaborator

    补充当前 main 固定 commit 5a5501b3e1048f3d19d96824cc68a62b7f0fcb07(本地 1 LOG/1 TN/1 CN)上的相关现象:原问题不是只在 prepared 路径出现。直接执行 SELECT point,eid FROM (SELECT 1 point,10 eid UNION ALL SELECT 2,20) u WHERE point>0,稳定返回 20101 相同宽度错误;UNION DISTINCT、INTERSECT、EXCEPT、CTE、外层窗口/JOIN 也可进入该错误路径。SQL PREPARE 以及 JDBC server-side prepare 复现。

    更需要注意的是,外层仅聚合第二列时,错误可变成静默错值:SELECT SUM(eid) FROM (SELECT 1 point,10 eid UNION ALL SELECT 2,20) u WHERE point>0 在 MO 稳定返回 12,MySQL 8.0.46 返回 30;MO 的 EXPLAIN VERBOSE 显示右分支 Project 输出 2 而非 20。INSERT ... SELECT 与 CTAS 可把该错值持久化。此错误结果已单列为 #30007,两个 issue 可能共用列重映射根因,请修复时一并验证。表对表 UNION ALL 和没有外层过滤的聚合为正常对照;失败的普通 INSERT/CTAS 未发现半写入。

  4. Ariznawlll commented on Oct 14, 2026

    @Ariznawlll
    Collaborator

    测试版本

    2026-10-14,MatrixOne 官方 main 2ce4e58af6f03b943ee288ffad81012766cf830a;隔离的本地单进程 LOG/TN/CN。修复 PR #30028 已合入。

    原问题验证

    原始带 UNION ALL 子查询、point>? 过滤和 ORDER BY point 的 prepared SQL 现在返回 (1,1),(2,1),(3,2),不再报子投影列数不匹配。MySQL 二进制 prepared 协议集成定向运行 3/3 通过。

    Happy Path 覆盖

    参数 0 返回精确三行;过滤后的 UNION 聚合 SUM(eid) 返回 30;prepared statement 重复执行结果一致。

    Unhappy Path 覆盖

    将参数改为 3 时返回空结果,而非投影重映射内部错误;执行后服务仍可查询。

    白盒验证

    修复版本的 SQL 集成定向测试 -count=3 通过,覆盖 prepared 与列裁剪;本次没有对所有 set operation 组合做穷举。

    回归测试

    MOTR PR #237 的 issue_29989_29980_25120_sql.py 固化 SQL PREPARE 正常/空过滤及聚合;定向脚本 3/3、整批定向 MOTR 9/9 通过。MOTR 使用 SQL PREPARE,二进制 prepared 路径由上述 MatrixOne 集成测试覆盖;完整 MOTR 套件未运行。

    测试证据

    修复 MatrixOne PR #30028,回归 MOTR PR #237。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

kind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions