Re: v17 Possible Union All Bug
David G. Johnston <david.g.johnston@gmail.com>
From: "David G. Johnston" <david.g.johnston@gmail.com>
To: PostgreSQL Bug List <pgsql-bugs@lists.postgresql.org>
Date: 2024-01-26T22:32:56Z
Lists: pgsql-bugs
On Tue, Jan 23, 2024 at 4:51 PM David G. Johnston <
david.g.johnston@gmail.com> wrote:
> I appreciate this is a bit of a messy test case. I'm willing to work on
> simplifying it further but figured I'd at least get confirmation of
> reproducibility and maybe someone will have an ah-ha! moment.
>
>
Decided to focus on simplifying the query first. I figured this out:
WITH cte_role_graph AS (
SELECT leaf_role.oid,
leaf_role.role_type,
leaf_role.rolname,
leaf_role.rolsuper,
array_to_string(ARRAY(
SELECT 'false' where false
UNION ALL
SELECT format('%I from %s'::text, 'test',
string_agg('test', '---'::text
ORDER BY grant_instance.level,
grant_instance.grantor, grant_instance.grantor_path
))
FROM unnest(leaf_role.memberof_groups) other(other)
JOIN pg_roles other_role ON other_role.oid =
other.other
JOIN rolegraph.role_relationship grant_instance ON
grant_instance.leaf_node = leaf_role.oid AND grant_instance.group_node =
other.other
JOIN pg_roles grant_role ON grant_role.oid =
grant_instance.grantor
GROUP BY other_role.rolname, grant_instance.via
), E'\n'::text) AS administration
FROM rolegraph.role_graph_detail leaf_role
where rolname ~ 'u6_green'
)
select * from cte_role_graph;
Running this query against the previously supplied dump file on HEAD should
produce the broken result. Simply commenting out the ORDER BY clause in
the string_agg causes the correct result to appear, even with the UNION ALL
present. Removing the union all and leaving the order by likewise still
produces the correct result.
psql (17devel)
Type "help" for help.
postgres=# \i tmp3.sql
oid | role_type | rolname | rolsuper | administration
-------+-----------+--------------------+----------+----------------
16405 | User | u6_green_leader_su | f | test from test+
| | | | test from test+
| | | | test from test+
| | | | test from test+
| | | | test from test
(1 row)
postgres=# \i tmp3.sql
oid | role_type | rolname | rolsuper | administration
-------+-----------+--------------------+----------+-----------------------
16405 | User | u6_green_leader_su | f | test from test +
| | | | test from test---test+
| | | | test from test +
| | | | test from test
(1 row)
David J.
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