Skip to content

[Bug] ROLLUP ORDER BY GROUPING fails with wrapped selected grouping keys #26269

Closed

Description

@Ariznawlll

Summary

WITH ROLLUP fails when grouping columns are wrapped only for display in the select list while ORDER BY directly uses GROUPING() and the original grouping columns.

Version

MatrixOne main at 4f82ab5476a798bb1c61903abf77a29a2f6c4fc8.

Reproduction

CREATE TABLE rollup_audit (
  region varchar(8),
  product varchar(8),
  amount int
);

INSERT INTO rollup_audit VALUES
  ('east', 'a', 10),
  ('east', 'b', 20),
  ('west', 'a', 30),
  (NULL, 'a', 5);

SELECT
  COALESCE(region, '<null>'),
  COALESCE(product, '<null>'),
  SUM(amount),
  GROUPING(region),
  GROUPING(product)
FROM rollup_audit
GROUP BY region, product WITH ROLLUP
ORDER BY GROUPING(region), region, GROUPING(product), product;

Actual behavior

MatrixOne returns:

ERROR 20301 (HY000): invalid input: column region does not exist

The result reproduces in three independent executions.

Expected behavior

The query should return the base groups, subtotals, and grand total. Local MySQL accepts the same SQL and returns eight rows. The GROUPING() values distinguish the source NULL group from the rollup rows.

Scope

The base ROLLUP query succeeds. The query also succeeds when either the display wrappers or the ORDER BY clause is removed. The failure requires their combination.

Activity

  1. added this to the MO-202607 milestone on Jul 27, 2026
  2. added
    kind/bug
    on Jul 27, 2026
  3. added theissue type on Jul 27, 2026
  4. added
    severity/s1
    and removed on Jul 29, 2026
  5. added a commit that references this issue on Jul 29, 2026
    ce6ce78
  6. removed
    severity/s1
    on Aug 6, 2026
  7. Ariznawlll commented on Aug 10, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

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

    原问题验证

    原始带显示包装、GROUPING() 和 ORDER BY 的 ROLLUP SQL 连续执行 3 次,均返回 8 行(明细、两级小计、总计),不再报 column region does not exist。

    Happy Path 覆盖

    1. 同时覆盖 COALESCE 显示包装、原始分组键排序和两个 GROUPING() 标记。
    2. 输入同时含普通分组和源数据 NULL 分组,8 行结果清楚区分源 NULL、小计和总计。

    Unhappy Path 覆盖

    1. 无匹配/空聚合不适用本 issue;该问题是只读合法 SQL 的 planner 绑定缺陷。
    2. 连续 3 轮均稳定返回完整聚合结果,无会话中断;无写入,因此失败原子性不适用。

    白盒验证

    不适用:使用公开 SQL 语义黑盒验证。

    回归测试

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

    测试证据

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

    测试结论

    测试通过。

  8. added 3 commits that reference this issue on Sep 17, 2026
    ba27c8b
    7f31224
    1b96508
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

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions