Skip to content

[Bug]: ORDER BY on a const-null projection panics in FixedLengthShuffle #26871

Closed

Description

@XuPeng-SH

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main; also reproduced on a 4.2-dev-derived build

Commit ID

08770e1beeb2 (v0.7.1-0.20260808145103-08770e1beeb2+dirty); 4.2-dev base 9301a23cc8f7c36aa0791b420aad8ed52e2ad3e6

Other Environment Information

  • Hardware parameters: local single-node MatrixOne, CN/TN memory cache 6 GB
  • OS type: Debian Linux 6.12.43 x86_64
  • Others: MySQL protocol port 6001

Actual Behavior

The query returns an internal panic instead of rows:

ERROR 20101 (HY000): internal error: panic runtime error: index out of range [0] with length 0
...
github.com/matrixorigin/matrixone/pkg/vectorize/shuffle.FixedLengthShuffle
  pkg/vectorize/shuffle/shuffle.go:23
github.com/matrixorigin/matrixone/pkg/container/vector.(*Vector).Shuffle
  pkg/container/vector/vector.go:2102
github.com/matrixorigin/matrixone/pkg/container/batch.(*Batch).Shuffle
  pkg/container/batch/batch.go:827
github.com/matrixorigin/matrixone/pkg/sql/colexec/order.(*container).sortAndSend
  pkg/sql/colexec/order/order.go:66

White-box observation: the projected INET_NTOA(NULL) is represented as a payload-free, zero-length const-null vector with a positive batch row count. The order operator passes it to Batch.Shuffle, and the fixed-length shuffle path indexes physical element 0 even though the const-null vector has no payload.

Expected Behavior

The query should return two NULL rows and must not panic.

Steps to Reproduce

DROP DATABASE IF EXISTS const_null_order_probe;
CREATE DATABASE const_null_order_probe;
USE const_null_order_probe;
CREATE TABLE t(a INT);
INSERT INTO t VALUES (1), (2);
SELECT INET_NTOA(NULL) AS empty_const_null FROM t ORDER BY a;

Additional information

Controls:

Activity

  1. added
    kind/bug
    on Aug 9, 2026
  2. added a commit that references this issue on Aug 10, 2026
    fc94c29
  3. Ariznawlll commented on Aug 10, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 分支:main
    • commit:3c7392a0f86b23712da71f31d7a9198a2c8591a9
    • 部署方式:本地单节点 Log/TN/CN,独立数据目录;测试日期:2026-08-10。

    原问题验证

    按 issue 的两行 INET_NTOA(NULL) + ORDER BY 复现 SQL 连续执行 3 次,均返回两行 NULL;无 panic、断连或服务重启。

    Happy Path 覆盖

    1. 两行主键表上,常量 NULL 投影经 ORDER BY 后仍保留两行 NULL。
    2. 同一组表函数/排序回归在 MOTR 连续 3 轮通过。

    Unhappy Path 覆盖

    1. 空输入/无投影行是本问题不触发排序物化的边界对照;不适用 SQL 失败原子性(本 issue 为只读 SELECT,原问题无非法输入契约)。
    2. 每轮后继续执行查询,服务和会话均可用。

    白盒验证

    不适用:本次按公开 SQL 黑盒验证,未使用 fault injection。

    回归测试

    已加入 motr PR #89 的 suites/14_issue_regression/t/issue_26871_26691_26431_order_apply_table_function.test(commit a6a50dfcf7053027dab5e9117fde7bdd7b5cdefb)。

    测试证据

    MOTR:上述用例及关联 5 个场景连续 3 轮,合计 15/15 成功、171 条断言成功。

    测试结论

    测试通过。

  4. added 3 commits that reference this issue on Sep 17, 2026
    95b5569
    e4d6e6a
    c330743
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