You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: GROUPING() in ORDER BY fails with column does not exist #25287
I searched existing issues for GROUPING ORDER BY column does not exist rollup and did not find a duplicate.
MatrixOne version
Verified on latest main at 200bfa7e0efb (fix: improve skills SKILL.md compatibility format (#25271)).
MySQL version
Local MySQL 8.3.0.
Reproduce steps
dropdatabase if exists repro_grouping_order_by;
createdatabaserepro_grouping_order_by;
use repro_grouping_order_by;
createtablet(region varchar(8), product varchar(8), amount int);
insert into t values
(null, 'tea', 10),
(null, 'tea', 20),
('east', null, 5),
('east', 'coffee', 7),
('east', 'tea', null),
('west', 'tea', 3);
select if(grouping(region), 'ROLLUP', if(region is null, 'NULL', region)) as region_label,
grouping(region) as grp_region,
if(grouping(product), 'ROLLUP', if(product is null, 'NULL', product)) as product_label,
grouping(product) as grp_product,
count(*) as count_all,
count(amount) as count_amount,
sum(amount) as sum_amount
from t
group by region, product with rollup
order by grouping(region), region_label, grouping(product), product_label;
Expected behavior
MySQL executes successfully and allows GROUPING() in ORDER BY for a WITH ROLLUP query.
Actual behavior
MatrixOne errors:
ERROR 20301 (HY000): invalid input: column region does not exist
Additional information
The same grouped result can be produced in MatrixOne if GROUPING(region) and GROUPING(product) are selected as aliases and those aliases are used for sorting. The issue appears specific to resolving GROUPING() directly inside ORDER BY.
SELECT IF(GROUPING(region), 'ROLLUP',
IF(region IS NULL, 'NULL', region)) AS region_label,
GROUPING(region) AS grp_region,
IF(GROUPING(product), 'ROLLUP',
IF(product IS NULL, 'NULL', product)) AS product_label,
GROUPING(product) AS grp_product,
COUNT(*) AS count_all,
COUNT(amount) AS count_amount,
SUM(amount) AS sum_amount
FROM grouping_source
GROUP BY region, product WITH ROLLUP
ORDER BY GROUPING(region), region_label,
GROUPING(product), product_label;
另外扩展验证 IF(GROUPING(region),1,0) 嵌套表达式直接用于 ORDER BY。
黑盒实际结果
原始 SQL 正常返回 9 行 ROLLUP 结果;
普通 NULL 分组与 ROLLUP NULL 可通过 GROUPING() 正确区分;
grand total 为 count_all=6、count_amount=5、sum_amount=45;
Activity
Ariznawlll commentedon Jul 27, 2026
最新 main 验证结果:通过
测试版本
main@cd8e175349932ccf4be8d388080a0c3310e538ac黑盒测试过程
按照 issue 原始数据创建包含普通值、NULL 和聚合 NULL 的表,执行:
另外扩展验证
IF(GROUPING(region),1,0)嵌套表达式直接用于ORDER BY。黑盒实际结果
GROUPING()正确区分;count_all=6、count_amount=5、sum_amount=45;IF(GROUPING(...))排序同样返回正确结果;column region does not exist。planner 定向测试
执行
GROUPING()直接排序、星号展开、select alias、prepared/reentrant、alias shadowing、二元表达式和嵌套表达式等 8 组用例,每组连续运行 3 轮,全部通过。结论
最新 main 已能在
WITH ROLLUP查询的ORDER BY中正确解析并执行GROUPING(),原问题已修复。Ariznawlll commentedon Jul 27, 2026
motr 黑盒回归
该问题已加入 matrixorigin/motr#66。
回归覆盖 issue 原始
GROUPING() + ORDER BY + WITH ROLLUP查询,以及IF(GROUPING(...))嵌套排序表达式。在 MatrixOne
main@cd8e175349932ccf4be8d388080a0c3310e538ac上录制后连续执行 3 轮,共 24 条 SQL,全部通过且输出一致。