"Where a = 1" generates a "Equivalenceclass" containing "a" and "1" ,
but in "grouping sets", a maybe generate nulls, so don't generate a "Equivalenceclass"
when a is not in all subsets of grouping sets.
select a,b,sum(10) as s from t1 where a = 1 group by grouping sets((a,b),(a)) order by a, s desc; -- ok,can generate Equivalenceclass
select a,b,sum(10) as s from t1 where a = 1 group by grouping sets((a,b),(b)) order by a, s desc; -- error, can't generate Equivalenceclass
原谅我蹩脚的英文,我们分析了原因,大致就是“a=1”这个条件生成等价类了,把a当成1处理了,但是实际上在带有grouping sets的sql中,
如果grouping sets的子集中有不包含a的group项,则a会被替换成null值,因此结果会错误;
我们的修改方案是生成等价类的时候,判断一下a是否在所有的grouping sets的子集都存在,如果有不存在的则不生产等价类。
谢谢。
Regards.
Zhang Mingli
www.hashdata.xyz
Do you mean order of null value (column a) is wrong?
Use NULLS FIRST/LAST to order null values.
On Jan 2, 2025 at 18:19 +0800, 谭忠涛 <zhongtao.tan@seaboxdata.com>, wrote:
Case:
create table t1(a int, b int);
insert into t1 values(1,1),(1,2);
select a,b,sum(10) as s from t1 where a = 1 group by rollup(a,b) order by a, s desc;