Re: v17 Possible Union All Bug
Andrei Lepikhov <a.lepikhov@postgrespro.ru>
From: Andrei Lepikhov <a.lepikhov@postgrespro.ru>
To: Alexander Korotkov <aekorotkov@gmail.com>,
"David G. Johnston" <david.g.johnston@gmail.com>
Cc: David Rowley <dgrowleyml@gmail.com>,
Alexander Korotkov <akorotkov@postgresql.org>,
PostgreSQL Bug List <pgsql-bugs@lists.postgresql.org>
Date: 2024-02-02T16:24:29Z
Lists: pgsql-bugs
On 1/2/2024 16:53, Andrei Lepikhov wrote:
> On 1/2/2024 11:06, Andrei Lepikhov wrote:
>>> Thank you for noticing. I'm investigating this.
>> Very curious bug. I simplified the test a bit (see in attachment), but
>> still can't replace system tables, like pg_authid, with a plain table.
>> Will try further.
> Just for speedup the bug scrutiny - new replay script attached.
A bit closer to the end. The symptom of the problem in incorrect order
of the columns in IncrementalSort, look:
-> GroupAggregate (actual time=1.136..1.157 rows=5 loops=1)
Output: format('%I from %s'::text, other_role.rolname,...
Group Key: grant_instance.via, other_role.rolname
-> Incremental Sort (actual time=1.098..1.102 rows=5 loops=1)
Output: other_role.rolname, grant_instance.via,...
Sort Key: grant_instance.grantor, other_role.rolname,...
Presorted Key: grant_instance.grantor
-> Merge Join (rows=5 loops=1)
Output: other_role.rolname, grant_instance.via,...
Merge Cond: (grant_role.oid = grant_instance.grantor)
Correct variant (without changing grouping order):
-> GroupAggregate (actual time=0.638..0.655 rows=4 loops=1)
Output: format('%I from %s'::text, other_role.rolname, ...
Group Key: other_role.rolname, grant_instance.via
-> Sort (actual time=0.626..0.630 rows=5 loops=1)
Output: other_role.rolname, grant_instance.via, ...
Sort Key: other_role.rolname, grant_instance.via, ...
-> Merge Join (rows=5 loops=1)
Output: other_role.rolname, grant_instance.via, ...
Merge Cond: (grant_role.oid = grant_instance.grantor)
But it is only a symptom. I can fix it easily, but what is the source?
As I see, we have the same value of sortref for the grouping column
other_role.rolname and for EquivalenceClass "grant_role.oid =
grant_instance.grantor".
We create sortref for other_role.rolname and grant_instance.via in
adjust_group_pathkeys_for_groupagg, because aggregate string_agg() in
the aggref->aggorder list contains both these columns.
I don't see ORDER BY for these columns in the query.
So Why is it happened? May it be a core bug?
--
regards,
Andrei Lepikhov
Postgres Professional
Commits
-
Fix usage of aggregate pathkeys in group_keys_reorder_by_pathkeys()
- c01f6ef46c8f 17.0 landed
-
Move is_valid_ascii() to ascii.h.
- 97287bdfae41 17.0 cited
-
Test EXPLAIN (FORMAT JSON) ... XMLTABLE
- 752533d40fd5 17.0 cited
-
Add test module injection_points
- 49cd2b93d7db 17.0 cited
-
Fix table name collision in tests in 0452b461bc
- c03d91d9be37 17.0 cited
-
Explore alternative orderings of group-by pathkeys during optimization.
- 0452b461bc40 17.0 cited
-
Generalize the common code of adding sort before processing of grouping
- 7ab80ac1caf9 17.0 cited
-
Reorder actions in ProcArrayApplyRecoveryInfo()
- c64086b79dba 17.0 cited
-
More documentation updates for incremental backup.
- 7b1dbf0a8d1d 17.0 cited
-
Avoid useless ReplicationOriginExitCleanup locking
- aa817c749657 17.0 cited