From: 谭忠涛 <zhongtao.tan@seaboxdata.com>
To: Zhang Mingli <zmlpostgres@gmail.com>
To: pgsql-bugs <pgsql-bugs@lists.postgresql.org>
Subject: 回复:Re: Incorrect sort result caused by ROLLUP and WHERE operation
Date: Fri, 3 Jan 2025 09:12:03 +0800
Message-ID: <tencent_6C58DF4466355D9E12876406@qq.com> (raw)
"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<zmlpostgres@gmail.com> 在 2025年1月2日 周四 18:50 写道:
Hi,
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;
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: zhongtao.tan@seaboxdata.com, zmlpostgres@gmail.com, pgsql-bugs@lists.postgresql.org
Subject: Re: 回复:Re: Incorrect sort result caused by ROLLUP and WHERE operation
In-Reply-To: <tencent_6C58DF4466355D9E12876406@qq.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox