Thread: 回复: BUG #18568: BUG: Result wrong when do group by on partition table!

回复: BUG #18568: BUG: Result wrong when do group by on partition table!

From
"狂奔的蜗牛"
Date:
I readd RelabelType to branch in v5 patch, and add case to cover the code.

In new adding case: `SELECT c collate "C", count(c) FROM pagg_tab3 GROUP BY c collate "C" HAVING count(c) > 1 ORDER BY 1;`
According to original logic, group_by_has_partkey() will return false, it will lead to cannot do having filter in sub table, the result is correct but the performance is poor.
Our logic will get better performance.


About InvalidOid collation, non-character type's collation is 0(InvalidOid) always.





 


------------------ 原始邮件 ------------------
发件人: "Tender Wang" <tndrwang@gmail.com>;
发送时间: 2024年8月7日(星期三) 下午5:23
收件人: "狂奔的蜗牛"<1105066510@qq.com>;
抄送: "pgsql-bugs"<pgsql-bugs@lists.postgresql.org>;"aleksander"<aleksander@timescale.com>;
主题: Re: BUG #18568: BUG: Result wrong when do group by on partition table!



狂奔的蜗牛 <1105066510@qq.com> 于2024年8月7日周三 16:06写道:
PartCollMatchesExprColl()  is not strict enough.
If partcoll == InvalidOid and groupcoll != InvalidOid, PartCollMatchesExprColl() return true always.
Just determine whether groupcoll is equal to partcoll, like this "partcoll == groupcoll".

I understand what you said. Actually, I keep it just curious when partcoll is InvalidOid.  Why it works for partition prune.
Is it not same between check partkey is equal to groupexpr and check partkey is equal to qualclause?


We cannot delete "if (IsA(groupexpr, RelableTyple) " branch, 
becasuse if groupexpr is RelabelType and  partcoll equal to groupcoll,  the "equal(groupexpr, partexpr) && PartKeyCollMatchesExprColl(partcoll, groupexpr_coll)" condition return false!!!
This is not what we expect.
 
" if groupexpr is RelabelType and  partcoll equal to groupcoll ", according to original logic, will return false in this situation. 
Now you think we can support above situation. Am I understand correctly? 
We're better to add more test case to cover the code if we're going to support this. The test cases now seem not going
into the RelableTyple branch.


We could rename "groupexpr_coll" to groupcoll, it looks more elegant.

No objection. You can continue to support RelableType situation and add more test cases based on V4.

--
Tender Wang
Attachment
On Wed, Aug 7, 2024 at 9:08 PM 狂奔的蜗牛 <1105066510@qq.com> wrote:
>
> I readd RelabelType to branch in v5 patch, and add case to cover the code.
>
> In new adding case: `SELECT c collate "C", count(c) FROM pagg_tab3 GROUP BY c collate "C" HAVING count(c) > 1 ORDER
BY1;` 
> According to original logic, group_by_has_partkey() will return false, it will lead to cannot do having filter in sub
table,the result is correct but the performance is poor. 
> Our logic will get better performance.
>
>
> About InvalidOid collation, non-character type's collation is 0(InvalidOid) always.
>

src/test/regress/sql/partition_aggregate.sql
suppose to run with or without ICU, your new test requires ICU,
which will make some buildfarm fail?

put the test to src/test/regress/sql/collate.icu.utf8.sql
seems a little bit of strange.



also. see beginning of partition_aggregate.sql
-- Note: to ensure plan stability, it's a good idea to make the partitions of
-- any one partitioned table in this test all have different numbers of rows.

you may want to adjust the pagg_tab3 partitions rows.



some white space error.
git diff --check
src/backend/optimizer/plan/planner.c:8041: trailing whitespace.
+                                        * Set collation in group by
clause using COLLATE syntax,
src/backend/optimizer/plan/planner.c:8051: trailing whitespace.
+                                       }



On Wed, Aug 7, 2024 at 11:04 PM jian he <jian.universality@gmail.com> wrote:
>
> On Wed, Aug 7, 2024 at 9:08 PM 狂奔的蜗牛 <1105066510@qq.com> wrote:
> >
> > I readd RelabelType to branch in v5 patch, and add case to cover the code.
> >


I did some minor adjustments in group_by_has_partkey, also refactored
the comment.

Attachment


jian he <jian.universality@gmail.com> 于2024年8月8日周四 15:51写道:
On Wed, Aug 7, 2024 at 11:04 PM jian he <jian.universality@gmail.com> wrote:
>
> On Wed, Aug 7, 2024 at 9:08 PM 狂奔的蜗牛 <1105066510@qq.com> wrote:
> >
> > I readd RelabelType to branch in v5 patch, and add case to cover the code.
> >


I did some minor adjustments in group_by_has_partkey, also refactored
the comment.

The logic in patch I think no problem. But I don't like the code style.

if (IsA(groupexpr, RelabelType))
     groupexpr = ((RelabelType *) groupexpr)->arg;
if (expr(groupexpr, partexr) && partcoll == groupcoll)
{
...
}

This looks more compact.

By the way, I think we'd better to include test cases together in your patch, then others can continue
to work based on your patch not need to go back to add the test cases.


--
Tender Wang

回复: BUG #18568: BUG: Result wrong when do group by on partition table!

From
"狂奔的蜗牛"
Date:
I agree with advice of code style, and I have trim trailing whitespace in V6 patch.

About test case added in file partition_aggregate.sql, for we create case_insentitive collation based on ICU, which regress sql file we should write is better ?
If write into collate.icu.utf8.sql, it seems not suitable.

 


------------------ 原始邮件 ------------------
发件人: "Tender Wang" <tndrwang@gmail.com>;
发送时间: 2024年8月8日(星期四) 下午4:20
收件人: "jian he"<jian.universality@gmail.com>;
抄送: "狂奔的蜗牛"<1105066510@qq.com>;"pgsql-bugs"<pgsql-bugs@lists.postgresql.org>;"aleksander"<aleksander@timescale.com>;
主题: Re: BUG #18568: BUG: Result wrong when do group by on partition table!



jian he <jian.universality@gmail.com> 于2024年8月8日周四 15:51写道:
On Wed, Aug 7, 2024 at 11:04 PM jian he <jian.universality@gmail.com> wrote:
>
> On Wed, Aug 7, 2024 at 9:08 PM 狂奔的蜗牛 <1105066510@qq.com> wrote:
> >
> > I readd RelabelType to branch in v5 patch, and add case to cover the code.
> >


I did some minor adjustments in group_by_has_partkey, also refactored
the comment.

The logic in patch I think no problem. But I don't like the code style.

if (IsA(groupexpr, RelabelType))
     groupexpr = ((RelabelType *) groupexpr)->arg;
if (expr(groupexpr, partexr) && partcoll == groupcoll)
{
...
}

This looks more compact.

By the way, I think we'd better to include test cases together in your patch, then others can continue
to work based on your patch not need to go back to add the test cases.


--
Tender Wang
Attachment


狂奔的蜗牛 <1105066510@qq.com> 于2024年8月8日周四 16:44写道:
I agree with advice of code style, and I have trim trailing whitespace in V6 patch.

The v6 patch still has code format issue, and the v6 looks almost same to v5.

git am v6-0001-fix-group_by_has_partkey-bug-and-add-regress-test.patch
Applying: fix-group_by_has_partkey-bug-and-add-regress-test
.git/rebase-apply/patch:31: trailing whitespace.
                                         * Set collation in group by clause using COLLATE syntax,
.git/rebase-apply/patch:41: trailing whitespace.
                                        } 

--
Tender Wang

回复: BUG #18568: BUG: Result wrong when do group by on partition table!

From
"狂奔的蜗牛"
Date:
Oh no! 
Sorry, I made a mistake on patch.
v7 is new patch.


 


------------------ 原始邮件 ------------------
发件人: "Tender Wang" <tndrwang@gmail.com>;
发送时间: 2024年8月8日(星期四) 下午5:46
收件人: "狂奔的蜗牛"<1105066510@qq.com>;
抄送: "jian he"<jian.universality@gmail.com>;"pgsql-bugs"<pgsql-bugs@lists.postgresql.org>;"aleksander"<aleksander@timescale.com>;
主题: Re: BUG #18568: BUG: Result wrong when do group by on partition table!



狂奔的蜗牛 <1105066510@qq.com> 于2024年8月8日周四 16:44写道:
I agree with advice of code style, and I have trim trailing whitespace in V6 patch.

The v6 patch still has code format issue, and the v6 looks almost same to v5.

git am v6-0001-fix-group_by_has_partkey-bug-and-add-regress-test.patch
Applying: fix-group_by_has_partkey-bug-and-add-regress-test
.git/rebase-apply/patch:31: trailing whitespace.
                                         * Set collation in group by clause using COLLATE syntax,
.git/rebase-apply/patch:41: trailing whitespace.
                                        } 

--
Tender Wang
Attachment