Skip to content

Commit a569eea

Browse files
committed
Add more tests for VACUUM skips with partitioned tables
A VACUUM or ANALYZE command listing directly a partitioned table expands it to its partitions, causing all elements of a tree to be processed with individual ownership checks done. This results in different relation skips depending on the ownership policy of a tree, which may not be consistent for a partition tree. This commit adds more tests to ensure that any future refactoring allows to keep a consistent behavior, or at least that any changes done are easily identified and checked. The current behavior of VACUUM with partitioned tables is present since 10. Author: Nathan Bossart Reviewed-by: Michael Paquier Discussion: https://postgr.es/m/DC186201-B01F-4A66-9EC4-F855A957C1F9@amazon.com
1 parent 88ebd62 commit a569eea

File tree

2 files changed

+156
-0
lines changed

2 files changed

+156
-0
lines changed

src/test/regress/expected/vacuum.out

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ DROP TABLE vactst;
124124
DROP TABLE vacparted;
125125
-- relation ownership, WARNING logs generated as all are skipped.
126126
CREATE TABLE vacowned (a int);
127+
CREATE TABLE vacowned_parted (a int) PARTITION BY LIST (a);
128+
CREATE TABLE vacowned_part1 PARTITION OF vacowned_parted FOR VALUES IN (1);
129+
CREATE TABLE vacowned_part2 PARTITION OF vacowned_parted FOR VALUES IN (2);
127130
CREATE ROLE regress_vacuum;
128131
SET ROLE regress_vacuum;
129132
-- Simple table
@@ -147,6 +150,102 @@ ANALYZE pg_catalog.pg_authid;
147150
WARNING: skipping "pg_authid" --- only superuser can analyze it
148151
VACUUM (ANALYZE) pg_catalog.pg_authid;
149152
WARNING: skipping "pg_authid" --- only superuser can vacuum it
153+
-- Partitioned table and its partitions, nothing owned by other user.
154+
-- Relations are not listed in a single command to test ownership
155+
-- independently.
156+
VACUUM vacowned_parted;
157+
WARNING: skipping "vacowned_parted" --- only table or database owner can vacuum it
158+
WARNING: skipping "vacowned_part1" --- only table or database owner can vacuum it
159+
WARNING: skipping "vacowned_part2" --- only table or database owner can vacuum it
160+
VACUUM vacowned_part1;
161+
WARNING: skipping "vacowned_part1" --- only table or database owner can vacuum it
162+
VACUUM vacowned_part2;
163+
WARNING: skipping "vacowned_part2" --- only table or database owner can vacuum it
164+
ANALYZE vacowned_parted;
165+
WARNING: skipping "vacowned_parted" --- only table or database owner can analyze it
166+
WARNING: skipping "vacowned_part1" --- only table or database owner can analyze it
167+
WARNING: skipping "vacowned_part2" --- only table or database owner can analyze it
168+
ANALYZE vacowned_part1;
169+
WARNING: skipping "vacowned_part1" --- only table or database owner can analyze it
170+
ANALYZE vacowned_part2;
171+
WARNING: skipping "vacowned_part2" --- only table or database owner can analyze it
172+
VACUUM (ANALYZE) vacowned_parted;
173+
WARNING: skipping "vacowned_parted" --- only table or database owner can vacuum it
174+
WARNING: skipping "vacowned_part1" --- only table or database owner can vacuum it
175+
WARNING: skipping "vacowned_part2" --- only table or database owner can vacuum it
176+
VACUUM (ANALYZE) vacowned_part1;
177+
WARNING: skipping "vacowned_part1" --- only table or database owner can vacuum it
178+
VACUUM (ANALYZE) vacowned_part2;
179+
WARNING: skipping "vacowned_part2" --- only table or database owner can vacuum it
180+
RESET ROLE;
181+
-- Partitioned table and one partition owned by other user.
182+
ALTER TABLE vacowned_parted OWNER TO regress_vacuum;
183+
ALTER TABLE vacowned_part1 OWNER TO regress_vacuum;
184+
SET ROLE regress_vacuum;
185+
VACUUM vacowned_parted;
186+
WARNING: skipping "vacowned_part2" --- only table or database owner can vacuum it
187+
VACUUM vacowned_part1;
188+
VACUUM vacowned_part2;
189+
WARNING: skipping "vacowned_part2" --- only table or database owner can vacuum it
190+
ANALYZE vacowned_parted;
191+
WARNING: skipping "vacowned_part2" --- only table or database owner can analyze it
192+
ANALYZE vacowned_part1;
193+
ANALYZE vacowned_part2;
194+
WARNING: skipping "vacowned_part2" --- only table or database owner can analyze it
195+
VACUUM (ANALYZE) vacowned_parted;
196+
WARNING: skipping "vacowned_part2" --- only table or database owner can vacuum it
197+
VACUUM (ANALYZE) vacowned_part1;
198+
VACUUM (ANALYZE) vacowned_part2;
199+
WARNING: skipping "vacowned_part2" --- only table or database owner can vacuum it
200+
RESET ROLE;
201+
-- Only one partition owned by other user.
202+
ALTER TABLE vacowned_parted OWNER TO CURRENT_USER;
203+
SET ROLE regress_vacuum;
204+
VACUUM vacowned_parted;
205+
WARNING: skipping "vacowned_parted" --- only table or database owner can vacuum it
206+
WARNING: skipping "vacowned_part2" --- only table or database owner can vacuum it
207+
VACUUM vacowned_part1;
208+
VACUUM vacowned_part2;
209+
WARNING: skipping "vacowned_part2" --- only table or database owner can vacuum it
210+
ANALYZE vacowned_parted;
211+
WARNING: skipping "vacowned_parted" --- only table or database owner can analyze it
212+
WARNING: skipping "vacowned_part2" --- only table or database owner can analyze it
213+
ANALYZE vacowned_part1;
214+
ANALYZE vacowned_part2;
215+
WARNING: skipping "vacowned_part2" --- only table or database owner can analyze it
216+
VACUUM (ANALYZE) vacowned_parted;
217+
WARNING: skipping "vacowned_parted" --- only table or database owner can vacuum it
218+
WARNING: skipping "vacowned_part2" --- only table or database owner can vacuum it
219+
VACUUM (ANALYZE) vacowned_part1;
220+
VACUUM (ANALYZE) vacowned_part2;
221+
WARNING: skipping "vacowned_part2" --- only table or database owner can vacuum it
222+
RESET ROLE;
223+
-- Only partitioned table owned by other user.
224+
ALTER TABLE vacowned_parted OWNER TO regress_vacuum;
225+
ALTER TABLE vacowned_part1 OWNER TO CURRENT_USER;
226+
SET ROLE regress_vacuum;
227+
VACUUM vacowned_parted;
228+
WARNING: skipping "vacowned_part1" --- only table or database owner can vacuum it
229+
WARNING: skipping "vacowned_part2" --- only table or database owner can vacuum it
230+
VACUUM vacowned_part1;
231+
WARNING: skipping "vacowned_part1" --- only table or database owner can vacuum it
232+
VACUUM vacowned_part2;
233+
WARNING: skipping "vacowned_part2" --- only table or database owner can vacuum it
234+
ANALYZE vacowned_parted;
235+
WARNING: skipping "vacowned_part1" --- only table or database owner can analyze it
236+
WARNING: skipping "vacowned_part2" --- only table or database owner can analyze it
237+
ANALYZE vacowned_part1;
238+
WARNING: skipping "vacowned_part1" --- only table or database owner can analyze it
239+
ANALYZE vacowned_part2;
240+
WARNING: skipping "vacowned_part2" --- only table or database owner can analyze it
241+
VACUUM (ANALYZE) vacowned_parted;
242+
WARNING: skipping "vacowned_part1" --- only table or database owner can vacuum it
243+
WARNING: skipping "vacowned_part2" --- only table or database owner can vacuum it
244+
VACUUM (ANALYZE) vacowned_part1;
245+
WARNING: skipping "vacowned_part1" --- only table or database owner can vacuum it
246+
VACUUM (ANALYZE) vacowned_part2;
247+
WARNING: skipping "vacowned_part2" --- only table or database owner can vacuum it
150248
RESET ROLE;
151249
DROP TABLE vacowned;
250+
DROP TABLE vacowned_parted;
152251
DROP ROLE regress_vacuum;

src/test/regress/sql/vacuum.sql

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ DROP TABLE vacparted;
9999

100100
-- relation ownership, WARNING logs generated as all are skipped.
101101
CREATE TABLE vacowned (a int);
102+
CREATE TABLE vacowned_parted (a int) PARTITION BY LIST (a);
103+
CREATE TABLE vacowned_part1 PARTITION OF vacowned_parted FOR VALUES IN (1);
104+
CREATE TABLE vacowned_part2 PARTITION OF vacowned_parted FOR VALUES IN (2);
102105
CREATE ROLE regress_vacuum;
103106
SET ROLE regress_vacuum;
104107
-- Simple table
@@ -113,6 +116,60 @@ VACUUM (ANALYZE) pg_catalog.pg_class;
113116
VACUUM pg_catalog.pg_authid;
114117
ANALYZE pg_catalog.pg_authid;
115118
VACUUM (ANALYZE) pg_catalog.pg_authid;
119+
-- Partitioned table and its partitions, nothing owned by other user.
120+
-- Relations are not listed in a single command to test ownership
121+
-- independently.
122+
VACUUM vacowned_parted;
123+
VACUUM vacowned_part1;
124+
VACUUM vacowned_part2;
125+
ANALYZE vacowned_parted;
126+
ANALYZE vacowned_part1;
127+
ANALYZE vacowned_part2;
128+
VACUUM (ANALYZE) vacowned_parted;
129+
VACUUM (ANALYZE) vacowned_part1;
130+
VACUUM (ANALYZE) vacowned_part2;
131+
RESET ROLE;
132+
-- Partitioned table and one partition owned by other user.
133+
ALTER TABLE vacowned_parted OWNER TO regress_vacuum;
134+
ALTER TABLE vacowned_part1 OWNER TO regress_vacuum;
135+
SET ROLE regress_vacuum;
136+
VACUUM vacowned_parted;
137+
VACUUM vacowned_part1;
138+
VACUUM vacowned_part2;
139+
ANALYZE vacowned_parted;
140+
ANALYZE vacowned_part1;
141+
ANALYZE vacowned_part2;
142+
VACUUM (ANALYZE) vacowned_parted;
143+
VACUUM (ANALYZE) vacowned_part1;
144+
VACUUM (ANALYZE) vacowned_part2;
145+
RESET ROLE;
146+
-- Only one partition owned by other user.
147+
ALTER TABLE vacowned_parted OWNER TO CURRENT_USER;
148+
SET ROLE regress_vacuum;
149+
VACUUM vacowned_parted;
150+
VACUUM vacowned_part1;
151+
VACUUM vacowned_part2;
152+
ANALYZE vacowned_parted;
153+
ANALYZE vacowned_part1;
154+
ANALYZE vacowned_part2;
155+
VACUUM (ANALYZE) vacowned_parted;
156+
VACUUM (ANALYZE) vacowned_part1;
157+
VACUUM (ANALYZE) vacowned_part2;
158+
RESET ROLE;
159+
-- Only partitioned table owned by other user.
160+
ALTER TABLE vacowned_parted OWNER TO regress_vacuum;
161+
ALTER TABLE vacowned_part1 OWNER TO CURRENT_USER;
162+
SET ROLE regress_vacuum;
163+
VACUUM vacowned_parted;
164+
VACUUM vacowned_part1;
165+
VACUUM vacowned_part2;
166+
ANALYZE vacowned_parted;
167+
ANALYZE vacowned_part1;
168+
ANALYZE vacowned_part2;
169+
VACUUM (ANALYZE) vacowned_parted;
170+
VACUUM (ANALYZE) vacowned_part1;
171+
VACUUM (ANALYZE) vacowned_part2;
116172
RESET ROLE;
117173
DROP TABLE vacowned;
174+
DROP TABLE vacowned_parted;
118175
DROP ROLE regress_vacuum;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy