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-23T23:51:52Z
Lists: pgsql-bugs
Attachments
- no-collapse.txt (text/plain)
- unionall-repro.sql (application/sql)
- collapse.txt (text/plain)
Hey,
The attached pg_dumpall file creates some test roles and some views, two of
which show the expected and problem behaviors. There is a lot going on
beneath these views but suffice to say I've granted admin of
g6c_service_manager_su to u6_green_leader_su twice, once with the bootstrap
superuser as the grantor and once with the cr_admin role as the grantor.
The query is supposed to notice that the otherwise identical grants have
two different grantors and combine them into a single newline separated
presentation. Note that both v16 examples below show this expected output
as does the "working" view in v17. The "broken" view in v17 decides not to
place them on separate lines.
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.
The only difference from the broken view to the working view is the entire
first union all subquery block beginning with the " 'mou' || " string be
prepended is removed. I.e., inside of the ARRAY there is no "union all" in
the working version, there is one (two subqueries) in the broken version.
Note that with this test data the "mou" subquery does not return any rows,
all output rows are coming from the "mog" one.
Results on a clean v17 head build from today:
psql (17devel)
Type "help" for help.
postgres=# select * from rolegraph.role_graph_broken;
oid | role_type | rolname | rolsuper |
administration
-------+-----------+--------------------+----------+-----------------------------------------------
16390 | User | u6_green_leader_su | f | mog of
g6a_fixedops_manager_su from superuser+
| | | | mog of
g6c_service_manager_su from superuser +
| | | | mog of
g6d_service_advisor_su from superuser +
| | | | mog of
g6e_service_tech_su from superuser +
| | | | mog of
g6c_service_manager_su from cr_admin
(1 row)
postgres=# select * from rolegraph.role_graph_working;
oid | role_type | rolname | rolsuper |
administration
-------+-----------+--------------------+----------+-----------------------------------------------
16390 | User | u6_green_leader_su | f | mog of
g6a_fixedops_manager_su from superuser+
| | | | mog of
g6c_service_manager_su from superuser +
| | | |
cr_admin +
| | | | mog of
g6d_service_advisor_su from superuser +
| | | | mog of
g6e_service_tech_su from superuser
(1 row)
Results on a clean v16 stable build from today:
postgres=# select * from rolegraph.role_graph_working;
oid | role_type | rolname | rolsuper |
administration
-------+-----------+--------------------+----------+-----------------------------------------------
16390 | User | u6_green_leader_su | f | mog of
g6a_fixedops_manager_su from superuser+
| | | | mog of
g6c_service_manager_su from superuser +
| | | |
cr_admin +
| | | | mog of
g6d_service_advisor_su from superuser +
| | | | mog of
g6e_service_tech_su from superuser
(1 row)
postgres=# select * from rolegraph.role_graph_broken;
oid | role_type | rolname | rolsuper |
administration
-------+-----------+--------------------+----------+-----------------------------------------------
16390 | User | u6_green_leader_su | f | mog of
g6a_fixedops_manager_su from superuser+
| | | | mog of
g6c_service_manager_su from superuser +
| | | |
cr_admin +
| | | | mog of
g6d_service_advisor_su from superuser +
| | | | mog of
g6e_service_tech_su from superuser
(1 row)
As an additional observation - I could swear I ran this last week on v17
without this particular error showing up so it seems like a recent thing.
Might end up giving me a chance to do my first git bisect...
I'm also attaching the explain analyze plans for the collapse (broken) and
no-collapse cases, from the v17 build.
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