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

From: 狂奔的蜗牛 <1105066510(at)qq(dot)com>
To: Tender Wang <tndrwang(at)gmail(dot)com>
Cc: pgsql-bugs <pgsql-bugs(at)lists(dot)postgresql(dot)org>, aleksander <aleksander(at)timescale(dot)com>
Subject: 回复: BUG #18568: BUG: Result wrong when do group by on partition table!
Date: 2024-08-07 08:06:15
Message-ID: tencent_197061097E814032292CF0A11A84672C3708@qq.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PartCollMatchesExprColl()&nbsp; 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".

We cannot delete "if (IsA(groupexpr, RelableTyple) " branch,&nbsp;
becasuse if groupexpr is RelabelType and&nbsp; partcoll equal to groupcoll,&nbsp; the "equal(groupexpr, partexpr) &amp;&amp; PartKeyCollMatchesExprColl(partcoll, groupexpr_coll)" condition return false!!!
This is not what we expect.

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

狂奔的蜗牛
1105066510(at)qq(dot)com

&nbsp;

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

狂奔的蜗牛 <1105066510(at)qq(dot)com&gt; 于2024年8月7日周三 13:35写道:

this case will enter `if (IsA(groupexpr, RelabelType))` branch.&nbsp;

We set "C" as groupkey's collation, and it's not equal to column's.
In transformGroupClause(), syntax `COLLATE xxx` will create CollateExpr node, and CollateExpr's arg is Var node.
And then, planner will call&nbsp;eval_const_expressions_mutator() to transform CollateExpr to RelableType if CollateExpr-&gt;collOid not equal to Collate-&gt;arg's collation.

Yech. Thanks for the explanation.
Because exprCollation() return the resultcollid if the nodetag is Relabletype, the expr() &amp;&amp; PartKeyCollMatchesExprColl() can handle this situation.
So we don't need "if (IsA(groupexpr, RelableTyple) " this branch.
&nbsp;

About V3 patch, PartCollMatchesExprColl() may be not&nbsp;suitable, because collation of partkey must be equal to groupkey's, even though they are all InvalidOid.

I'm not sure about what you said.&nbsp; I uesd it because partition prune do this way. I keep it temporarily.&nbsp;

The test case in v3 patch only has EXPLAIN statement. I add SELECT statement and make the result more stable according to Aleksander advices.

--
Tender Wang

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tender Wang 2024-08-07 09:23:21 Re: BUG #18568: BUG: Result wrong when do group by on partition table!
Previous Message Sandeep Thakkar 2024-08-07 07:45:01 Re: BUG #18572: Crash during postgresql-16.3-2-windows-x64.exe installation