Skip to content

[Bug]: GROUP_CONCAT with ORDER BY panics with index out of range #24359

Closed

Description

@Ariznawlll

Branch

3.0-dev (git_version 5c1a345)

Actual Behavior

GROUP_CONCAT with multiple arguments and ORDER BY triggers a panic:

ERROR 20101 (HY000): internal error: panic runtime error: index out of range [1] with length 1:
runtime.goPanicIndex
    /home/github/go/pkg/mod/golang.org/[email protected]/src/runtime/panic.go:115
github.com/matrixorigin/matrixone/pkg/sql/colexec/aggexec.(*groupConcatExec).Fill

Reproduction

SELECT GROUP_CONCAT(attname, ':', att_length ORDER BY attnum)
FROM mo_catalog.mo_columns
WHERE att_database='mo_catalog' AND att_relname='mo_columns' LIMIT 1;

Root Cause

(*groupConcatExec).Fill in pkg/sql/colexec/aggexec accesses an index beyond the slice length when the function has multiple expression arguments combined with an ORDER BY clause.

Expected Behavior

Should return the concatenated string of column values separated by the specified separator, ordered by attnum.

Impact

Any query using GROUP_CONCAT with multiple arguments + ORDER BY will crash the CN with a panic. This is a server-crash-level bug.

Activity

  1. added
    kind/bug
    on May 12, 2026
  2. added theissue type on May 12, 2026
  3. added this to the MO-202605 milestone on May 12, 2026
  4. self-assigned this
    on May 13, 2026
  5. daviszhen commented on May 13, 2026

    @daviszhen
    Contributor

    我看看

  6. daviszhen commented on May 18, 2026

    @daviszhen
    Contributor

    main上group_concat的改写也是错误的. issue暂时不能close

  7. added
    ai-light
    on Jul 1, 2026
  8. added
    severity/s0
    on Jul 27, 2026
  9. added a commit that references this issue on Jul 29, 2026
    f41a6d1
  10. Ariznawlll commented on Jul 30, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main(截至 2026-07-30 16:30,Asia/Shanghai)
    • commit:41332062a6740978f269088a92ee362a888c7bd7
    • 部署方式:从该官方 commit 源码构建;etc/launch-with-proxy/launch.toml(2 CN + 1 TN + Proxy),SQL 入口 127.0.0.1:6001
    • 测试日期:2026-07-30

    原问题验证

    执行 issue 原始 catalog 查询 GROUP_CONCAT(attname,':',att_length ORDER BY attnum),返回非空有序结果,未出现 index out of range/panic;完整黑盒 3/3 通过。

    Happy Path 覆盖

    1. 多表达式参数配合单键 ASC、DESC 和自定义 SEPARATOR 结果正确。
    2. 多排序键、DISTINCT、grouped/ungrouped 和全 NULL 分组结果正确。
    3. catalog 原始大字符串聚合正常。

    Unhappy Path 覆盖

    1. NULL 参数行被按 GROUP_CONCAT 语义跳过,全 NULL 分组返回 NULL。
    2. 白盒覆盖非法 payload、截断 run data、取消和 spill 边界,均返回受控结果,无 panic。

    白盒验证

    ordered GROUP_CONCAT、spill/cancellation、payload validation 定向 UT 连续 3 轮通过;aggexec 定向 -race 通过。

    回归测试

    修复提交 f41a6d112 已扩展 test/distributed/cases/function/function_group_concat.sql 并加入完整 aggexec/group UT。

    测试证据

    完整 3 轮 SQL 结果、测试脚本、Proxy 黑盒日志、定向 UT 与 -race 输出:https://gist.github.com/Ariznawlll/b8f1a22642a58fd5264482687534728b

    测试结论

    测试通过。

  11. Ariznawlll commented on Jul 30, 2026

    @Ariznawlll
    CollaboratorAuthor

    motr 黑盒回归已补充

    • PR:matrixorigin/motr#72
    • 用例:suites/14_issue_regression/t/issue_24359_ordered_group_concat.test
    • 覆盖:多参数有序 GROUP_CONCAT、DISTINCT、分组、catalog 形状聚合均有确定断言
    • 本地验证:基于 MatrixOne main@41332062a6740978f269088a92ee362a888c7bd7,该批 14 个用例连续 3 轮为 42/42 成功(504/504 语句);完整 14_issue_regression suite 为 124 成功、0 失败。
  12. added 3 commits that reference this issue on Sep 17, 2026
    c53855a
    9c2e35b
    6171780
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Bug fixai-lightkind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions