From a5600b5e9c1cb54d0890ce70340555b879988b48 Mon Sep 17 00:00:00 2001 From: amitlan Date: Wed, 18 Jan 2023 16:49:49 +0900 Subject: [PATCH v3 1/3] Add test case to test a bug of build_simple_rel() This is trying to add a test case similar to those added in 553d2ec2710 such that they exercise a query having UNION ALL over selects from a view over a partitioned table. --- src/test/regress/expected/inherit.out | 39 +++++++++++++++++++++++++-- src/test/regress/sql/inherit.sql | 27 +++++++++++++++++-- 2 files changed, 62 insertions(+), 4 deletions(-) diff --git a/src/test/regress/expected/inherit.out b/src/test/regress/expected/inherit.out index 2d49e765de..143271cd62 100644 --- a/src/test/regress/expected/inherit.out +++ b/src/test/regress/expected/inherit.out @@ -2512,9 +2512,44 @@ explain (costs off) (6 rows) reset session authorization; -revoke all on permtest_parent from regress_no_child_access; -drop role regress_no_child_access; +-- Check with a view over permtest_parent and a UNION ALL over the view, +-- especially that permtest_parent's permissions are checked with the role +-- owning the view as permtest_parent's RTE's checkAsUser. +create role regress_permtest_view_owner; +revoke all on permtest_grandchild from regress_permtest_view_owner; +grant select(a, c) on permtest_parent to regress_permtest_view_owner; +create view permtest_parent_view as + select a, c from permtest_parent; +alter view permtest_parent_view owner to regress_permtest_view_owner; +-- Like above, the 2nd arm of UNION ALL gets a hash join due to lack of access +-- to the expression index's stats +revoke select on permtest_parent_view from regress_no_child_access; +grant select(a,c) on permtest_parent_view to regress_no_child_access; +set session authorization regress_no_child_access; +explain (costs off) + select p1.a, p2.c from + (select * from permtest_parent_view + union all + select * from permtest_parent_view) p1 + inner join permtest_parent p2 on p1.a = p2.a and left(p1.c, 3) ~ 'a1$'; + QUERY PLAN +--------------------------------------------------------------------- + Hash Join + Hash Cond: (p2.a = permtest_parent.a) + -> Seq Scan on permtest_grandchild p2 + -> Hash + -> Append + -> Seq Scan on permtest_grandchild permtest_parent + Filter: ("left"(c, 3) ~ 'a1$'::text) + -> Seq Scan on permtest_grandchild permtest_parent_1 + Filter: ("left"(c, 3) ~ 'a1$'::text) +(9 rows) + +reset session authorization; +drop view permtest_parent_view; drop table permtest_parent; +drop role regress_permtest_view_owner; +drop role regress_no_child_access; -- Verify that constraint errors across partition root / child are -- handled correctly (Bug #16293) CREATE TABLE errtst_parent ( diff --git a/src/test/regress/sql/inherit.sql b/src/test/regress/sql/inherit.sql index 195aedb5ff..3a936298d7 100644 --- a/src/test/regress/sql/inherit.sql +++ b/src/test/regress/sql/inherit.sql @@ -907,9 +907,32 @@ explain (costs off) select p2.a, p1.c from permtest_parent p1 inner join permtest_parent p2 on p1.a = p2.a and left(p1.c, 3) ~ 'a1$'; reset session authorization; -revoke all on permtest_parent from regress_no_child_access; -drop role regress_no_child_access; + +-- Check with a view over permtest_parent and a UNION ALL over the view, +-- especially that permtest_parent's permissions are checked with the role +-- owning the view as permtest_parent's RTE's checkAsUser. +create role regress_permtest_view_owner; +revoke all on permtest_grandchild from regress_permtest_view_owner; +grant select(a, c) on permtest_parent to regress_permtest_view_owner; +create view permtest_parent_view as + select a, c from permtest_parent; +alter view permtest_parent_view owner to regress_permtest_view_owner; +-- Like above, the 2nd arm of UNION ALL gets a hash join due to lack of access +-- to the expression index's stats +revoke select on permtest_parent_view from regress_no_child_access; +grant select(a,c) on permtest_parent_view to regress_no_child_access; +set session authorization regress_no_child_access; +explain (costs off) + select p1.a, p2.c from + (select * from permtest_parent_view + union all + select * from permtest_parent_view) p1 + inner join permtest_parent p2 on p1.a = p2.a and left(p1.c, 3) ~ 'a1$'; +reset session authorization; +drop view permtest_parent_view; drop table permtest_parent; +drop role regress_permtest_view_owner; +drop role regress_no_child_access; -- Verify that constraint errors across partition root / child are -- handled correctly (Bug #16293) -- 2.35.3