Skip to content

Commit 4002b4e

Browse files
committed
Add a variant expected output for the 'repack' regression test
so that older versions of Postgres (pre-c7e27bec) will still pass tests. Also fix the 'tablespace' test the same way.
1 parent ab70a01 commit 4002b4e

File tree

2 files changed

+623
-0
lines changed

2 files changed

+623
-0
lines changed

regress/expected/repack_2.out

Lines changed: 389 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,389 @@
1+
SET client_min_messages = warning;
2+
--
3+
-- create table.
4+
--
5+
CREATE TABLE tbl_cluster (
6+
col1 int,
7+
"time" timestamp,
8+
","")" text,
9+
PRIMARY KEY (","")", col1) WITH (fillfactor = 75)
10+
) WITH (fillfactor = 70);
11+
CREATE INDEX ","") cluster" ON tbl_cluster ("time", length(","")"), ","")" text_pattern_ops) WITH (fillfactor = 75);
12+
ALTER TABLE tbl_cluster CLUSTER ON ","") cluster";
13+
CREATE TABLE tbl_only_pkey (
14+
col1 int PRIMARY KEY,
15+
","")" text
16+
);
17+
CREATE TABLE tbl_only_ckey (
18+
col1 int,
19+
col2 timestamp,
20+
","")" text
21+
) WITH (fillfactor = 70);
22+
CREATE INDEX cidx_only_ckey ON tbl_only_ckey (col2, ","")");
23+
ALTER TABLE tbl_only_ckey CLUSTER ON cidx_only_ckey;
24+
CREATE TABLE tbl_gistkey (
25+
id integer PRIMARY KEY,
26+
c circle
27+
);
28+
CREATE INDEX cidx_circle ON tbl_gistkey USING gist (c);
29+
ALTER TABLE tbl_gistkey CLUSTER ON cidx_circle;
30+
CREATE TABLE tbl_with_dropped_column (
31+
d1 text,
32+
c1 text,
33+
id integer PRIMARY KEY,
34+
d2 text,
35+
c2 text,
36+
d3 text
37+
);
38+
ALTER INDEX tbl_with_dropped_column_pkey SET (fillfactor = 75);
39+
ALTER TABLE tbl_with_dropped_column CLUSTER ON tbl_with_dropped_column_pkey;
40+
CREATE INDEX idx_c1c2 ON tbl_with_dropped_column (c1, c2) WITH (fillfactor = 75);
41+
CREATE INDEX idx_c2c1 ON tbl_with_dropped_column (c2, c1);
42+
CREATE TABLE tbl_with_dropped_toast (
43+
i integer,
44+
j integer,
45+
t text,
46+
PRIMARY KEY (i, j)
47+
);
48+
ALTER TABLE tbl_with_dropped_toast CLUSTER ON tbl_with_dropped_toast_pkey;
49+
CREATE TABLE tbl_badindex (
50+
id integer PRIMARY KEY,
51+
n integer
52+
);
53+
CREATE TABLE tbl_idxopts (
54+
i integer PRIMARY KEY,
55+
t text
56+
);
57+
CREATE INDEX idxopts_t ON tbl_idxopts (t DESC NULLS LAST) WHERE (t != 'aaa');
58+
--
59+
-- insert data
60+
--
61+
INSERT INTO tbl_cluster VALUES(1, '2008-12-31 10:00:00', 'admin');
62+
INSERT INTO tbl_cluster VALUES(2, '2008-01-01 00:00:00', 'king');
63+
INSERT INTO tbl_cluster VALUES(3, '2008-03-04 12:00:00', 'joker');
64+
INSERT INTO tbl_cluster VALUES(4, '2008-03-05 15:00:00', 'queen');
65+
INSERT INTO tbl_cluster VALUES(5, '2008-01-01 00:30:00', sqrt(2::numeric(1000,999))::text || sqrt(3::numeric(1000,999))::text);
66+
INSERT INTO tbl_only_pkey VALUES(1, 'abc');
67+
INSERT INTO tbl_only_pkey VALUES(2, 'def');
68+
INSERT INTO tbl_only_ckey VALUES(1, '2008-01-01 00:00:00', 'abc');
69+
INSERT INTO tbl_only_ckey VALUES(2, '2008-02-01 00:00:00', 'def');
70+
INSERT INTO tbl_gistkey VALUES(1, '<(1,2),3>');
71+
INSERT INTO tbl_gistkey VALUES(2, '<(4,5),6>');
72+
INSERT INTO tbl_with_dropped_column VALUES('d1', 'c1', 2, 'd2', 'c2', 'd3');
73+
INSERT INTO tbl_with_dropped_column VALUES('d1', 'c1', 1, 'd2', 'c2', 'd3');
74+
ALTER TABLE tbl_with_dropped_column DROP COLUMN d1;
75+
ALTER TABLE tbl_with_dropped_column DROP COLUMN d2;
76+
ALTER TABLE tbl_with_dropped_column DROP COLUMN d3;
77+
ALTER TABLE tbl_with_dropped_column ADD COLUMN c3 text;
78+
CREATE VIEW view_for_dropped_column AS
79+
SELECT * FROM tbl_with_dropped_column;
80+
INSERT INTO tbl_with_dropped_toast VALUES(1, 10, 'abc');
81+
INSERT INTO tbl_with_dropped_toast VALUES(2, 20, sqrt(2::numeric(1000,999))::text || sqrt(3::numeric(1000,999))::text);
82+
ALTER TABLE tbl_with_dropped_toast DROP COLUMN t;
83+
INSERT INTO tbl_badindex VALUES(1, 10);
84+
INSERT INTO tbl_badindex VALUES(2, 10);
85+
-- This will fail. Silence the message as it's different across PG versions.
86+
SET client_min_messages = fatal;
87+
CREATE UNIQUE INDEX CONCURRENTLY idx_badindex_n ON tbl_badindex (n);
88+
SET client_min_messages = warning;
89+
INSERT INTO tbl_idxopts VALUES (0, 'abc'), (1, 'aaa'), (2, NULL), (3, 'bbb');
90+
--
91+
-- before
92+
--
93+
SELECT * FROM tbl_with_dropped_column;
94+
c1 | id | c2 | c3
95+
----+----+----+----
96+
c1 | 2 | c2 |
97+
c1 | 1 | c2 |
98+
(2 rows)
99+
100+
SELECT * FROM view_for_dropped_column;
101+
c1 | id | c2 | c3
102+
----+----+----+----
103+
c1 | 2 | c2 |
104+
c1 | 1 | c2 |
105+
(2 rows)
106+
107+
SELECT * FROM tbl_with_dropped_toast;
108+
i | j
109+
---+----
110+
1 | 10
111+
2 | 20
112+
(2 rows)
113+
114+
--
115+
-- do repack
116+
--
117+
\! pg_repack --dbname=contrib_regression --table=tbl_cluster
118+
INFO: repacking table "tbl_cluster"
119+
\! pg_repack --dbname=contrib_regression --table=tbl_badindex
120+
INFO: repacking table "tbl_badindex"
121+
WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON tbl_badindex USING btree (n)
122+
\! pg_repack --dbname=contrib_regression
123+
INFO: repacking table "tbl_cluster"
124+
INFO: repacking table "tbl_only_pkey"
125+
INFO: repacking table "tbl_gistkey"
126+
INFO: repacking table "tbl_with_dropped_column"
127+
INFO: repacking table "tbl_with_dropped_toast"
128+
INFO: repacking table "tbl_badindex"
129+
WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON tbl_badindex USING btree (n)
130+
INFO: repacking table "tbl_idxopts"
131+
--
132+
-- after
133+
--
134+
\d tbl_cluster
135+
Table "public.tbl_cluster"
136+
Column | Type | Modifiers
137+
--------+-----------------------------+-----------
138+
col1 | integer | not null
139+
time | timestamp without time zone |
140+
,") | text | not null
141+
Indexes:
142+
"tbl_cluster_pkey" PRIMARY KEY, btree (","")", col1) WITH (fillfactor=75)
143+
",") cluster" btree ("time", length(","")"), ","")" text_pattern_ops) WITH (fillfactor=75) CLUSTER
144+
145+
\d tbl_gistkey
146+
Table "public.tbl_gistkey"
147+
Column | Type | Modifiers
148+
--------+---------+-----------
149+
id | integer | not null
150+
c | circle |
151+
Indexes:
152+
"tbl_gistkey_pkey" PRIMARY KEY, btree (id)
153+
"cidx_circle" gist (c) CLUSTER
154+
155+
\d tbl_only_ckey
156+
Table "public.tbl_only_ckey"
157+
Column | Type | Modifiers
158+
--------+-----------------------------+-----------
159+
col1 | integer |
160+
col2 | timestamp without time zone |
161+
,") | text |
162+
Indexes:
163+
"cidx_only_ckey" btree (col2, ","")") CLUSTER
164+
165+
\d tbl_only_pkey
166+
Table "public.tbl_only_pkey"
167+
Column | Type | Modifiers
168+
--------+---------+-----------
169+
col1 | integer | not null
170+
,") | text |
171+
Indexes:
172+
"tbl_only_pkey_pkey" PRIMARY KEY, btree (col1)
173+
174+
\d tbl_with_dropped_column
175+
Table "public.tbl_with_dropped_column"
176+
Column | Type | Modifiers
177+
--------+---------+-----------
178+
c1 | text |
179+
id | integer | not null
180+
c2 | text |
181+
c3 | text |
182+
Indexes:
183+
"tbl_with_dropped_column_pkey" PRIMARY KEY, btree (id) WITH (fillfactor=75) CLUSTER
184+
"idx_c1c2" btree (c1, c2) WITH (fillfactor=75)
185+
"idx_c2c1" btree (c2, c1)
186+
187+
\d tbl_with_dropped_toast
188+
Table "public.tbl_with_dropped_toast"
189+
Column | Type | Modifiers
190+
--------+---------+-----------
191+
i | integer | not null
192+
j | integer | not null
193+
Indexes:
194+
"tbl_with_dropped_toast_pkey" PRIMARY KEY, btree (i, j) CLUSTER
195+
196+
\d tbl_idxopts
197+
Table "public.tbl_idxopts"
198+
Column | Type | Modifiers
199+
--------+---------+-----------
200+
i | integer | not null
201+
t | text |
202+
Indexes:
203+
"tbl_idxopts_pkey" PRIMARY KEY, btree (i)
204+
"idxopts_t" btree (t DESC NULLS LAST) WHERE t <> 'aaa'::text
205+
206+
SELECT col1, to_char("time", 'YYYY-MM-DD HH24:MI:SS'), ","")" FROM tbl_cluster;
207+
col1 | to_char | ,")
208+
------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
209+
2 | 2008-01-01 00:00:00 | king
210+
5 | 2008-01-01 00:30:00 | 1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727350138462309122970249248360558507372126441214970999358314132226659275055927557999505011527820605714701095599716059702745345968620147285174186408891986095523292304843087143214508397626036279952514079896872533965463318088296406206152583523950547457502877599617298355752203375318570113543746034084988471603868999706990048150305440277903164542478230684929369186215805784631115966687130130156185689872372352885092648612494977154218334204285686060146824720771435854874155657069677653720226485447015858801620758474922657226002085584466521458398893944370926591800311388246468157082630100594858704003186480342194897278290641045072636881313739855256117322040245091227700226941127573627280495738108967504018369868368450725799364729060762996941380475654823728997180326802474420629269124859052181004459842150591120249441341728531478105803603371077309182869314710171111683916581726889419758716582152128229518488471.732050807568877293527446341505872366942805253810380628055806979451933016908800037081146186757248575675626141415406703029969945094998952478811655512094373648528093231902305582067974820101084674923265015312343266903322886650672254668921837971227047131660367861588019049986537379859389467650347506576050756618348129606100947602187190325083145829523959832997789824508288714463832917347224163984587855397667958063818353666110843173780894378316102088305524901670023520711144288695990956365797087168498072899493296484283020786408603988738697537582317317831395992983007838702877053913369563312103707264019249106768231199288375641141422016742752102372994270831059898459475987664288897796147837958390228854852903576033852808064381972344661059689722872865264153822664698420021195484155278441181286534507035191650016689294415480846071277143999762926834629577438361895110127148638746976545982451788550975379013880664961911962222957110555242923723192197738262561631468842032853716682938649611917049738836395495938
211+
3 | 2008-03-04 12:00:00 | joker
212+
4 | 2008-03-05 15:00:00 | queen
213+
1 | 2008-12-31 10:00:00 | admin
214+
(5 rows)
215+
216+
SELECT * FROM tbl_only_ckey ORDER BY 1;
217+
col1 | col2 | ,")
218+
------+--------------------------+-----
219+
1 | Tue Jan 01 00:00:00 2008 | abc
220+
2 | Fri Feb 01 00:00:00 2008 | def
221+
(2 rows)
222+
223+
SELECT * FROM tbl_only_pkey ORDER BY 1;
224+
col1 | ,")
225+
------+-----
226+
1 | abc
227+
2 | def
228+
(2 rows)
229+
230+
SELECT * FROM tbl_gistkey ORDER BY 1;
231+
id | c
232+
----+-----------
233+
1 | <(1,2),3>
234+
2 | <(4,5),6>
235+
(2 rows)
236+
237+
SET enable_seqscan = on;
238+
SET enable_indexscan = off;
239+
SELECT * FROM tbl_with_dropped_column;
240+
c1 | id | c2 | c3
241+
----+----+----+----
242+
c1 | 1 | c2 |
243+
c1 | 2 | c2 |
244+
(2 rows)
245+
246+
SELECT * FROM view_for_dropped_column;
247+
c1 | id | c2 | c3
248+
----+----+----+----
249+
c1 | 1 | c2 |
250+
c1 | 2 | c2 |
251+
(2 rows)
252+
253+
SELECT * FROM tbl_with_dropped_toast;
254+
i | j
255+
---+----
256+
1 | 10
257+
2 | 20
258+
(2 rows)
259+
260+
SET enable_seqscan = off;
261+
SET enable_indexscan = on;
262+
SELECT * FROM tbl_with_dropped_column;
263+
c1 | id | c2 | c3
264+
----+----+----+----
265+
c1 | 1 | c2 |
266+
c1 | 2 | c2 |
267+
(2 rows)
268+
269+
SELECT * FROM view_for_dropped_column;
270+
c1 | id | c2 | c3
271+
----+----+----+----
272+
c1 | 1 | c2 |
273+
c1 | 2 | c2 |
274+
(2 rows)
275+
276+
SELECT * FROM tbl_with_dropped_toast;
277+
i | j
278+
---+----
279+
1 | 10
280+
2 | 20
281+
(2 rows)
282+
283+
RESET enable_seqscan;
284+
RESET enable_indexscan;
285+
--
286+
-- check broken links or orphan toast relations
287+
--
288+
SELECT oid, relname
289+
FROM pg_class
290+
WHERE relkind = 't'
291+
AND oid NOT IN (SELECT reltoastrelid FROM pg_class WHERE relkind = 'r');
292+
oid | relname
293+
-----+---------
294+
(0 rows)
295+
296+
SELECT oid, relname
297+
FROM pg_class
298+
WHERE relkind = 'r'
299+
AND reltoastrelid <> 0
300+
AND reltoastrelid NOT IN (SELECT oid FROM pg_class WHERE relkind = 't');
301+
oid | relname
302+
-----+---------
303+
(0 rows)
304+
305+
--
306+
-- NOT NULL UNIQUE
307+
--
308+
CREATE TABLE tbl_nn (col1 int NOT NULL, col2 int NOT NULL);
309+
CREATE TABLE tbl_uk (col1 int NOT NULL, col2 int , UNIQUE(col1, col2));
310+
CREATE TABLE tbl_nn_uk (col1 int NOT NULL, col2 int NOT NULL, UNIQUE(col1, col2));
311+
CREATE TABLE tbl_pk_uk (col1 int NOT NULL, col2 int NOT NULL, PRIMARY KEY(col1, col2), UNIQUE(col2, col1));
312+
CREATE TABLE tbl_nn_puk (col1 int NOT NULL, col2 int NOT NULL);
313+
CREATE UNIQUE INDEX tbl_nn_puk_pcol1_idx ON tbl_nn_puk(col1) WHERE col1 < 10;
314+
\! pg_repack --dbname=contrib_regression --table=tbl_nn
315+
WARNING: relation "tbl_nn" must have a primary key or not-null unique keys
316+
-- => WARNING
317+
\! pg_repack --dbname=contrib_regression --table=tbl_uk
318+
WARNING: relation "tbl_uk" must have a primary key or not-null unique keys
319+
-- => WARNING
320+
\! pg_repack --dbname=contrib_regression --table=tbl_nn_uk
321+
INFO: repacking table "tbl_nn_uk"
322+
-- => OK
323+
\! pg_repack --dbname=contrib_regression --table=tbl_pk_uk
324+
INFO: repacking table "tbl_pk_uk"
325+
-- => OK
326+
\! pg_repack --dbname=contrib_regression --table=tbl_pk_uk --only-indexes
327+
INFO: repacking indexes of "tbl_pk_uk"
328+
INFO: repacking index "public"."tbl_pk_uk_col2_col1_key"
329+
INFO: repacking index "public"."tbl_pk_uk_pkey"
330+
-- => OK
331+
\! pg_repack --dbname=contrib_regression --table=tbl_nn_puk
332+
WARNING: relation "tbl_nn_puk" must have a primary key or not-null unique keys
333+
-- => WARNING
334+
--
335+
-- Triggers handling
336+
--
337+
CREATE FUNCTION trgtest() RETURNS trigger AS
338+
$$BEGIN RETURN NEW; END$$
339+
LANGUAGE plpgsql;
340+
CREATE TABLE trg1 (id integer PRIMARY KEY);
341+
CREATE TRIGGER z_repack_triggeq BEFORE UPDATE ON trg1 FOR EACH ROW EXECUTE PROCEDURE trgtest();
342+
\! pg_repack --dbname=contrib_regression --table=trg1
343+
INFO: repacking table "trg1"
344+
CREATE TABLE trg2 (id integer PRIMARY KEY);
345+
CREATE TRIGGER z_repack_trigger BEFORE UPDATE ON trg2 FOR EACH ROW EXECUTE PROCEDURE trgtest();
346+
\! pg_repack --dbname=contrib_regression --table=trg2
347+
INFO: repacking table "trg2"
348+
WARNING: the table "trg2" already has a trigger called "z_repack_trigger"
349+
DETAIL: The trigger was probably installed during a previous attempt to run pg_repack on the table which was interrupted and for some reason failed to clean up the temporary objects. Please drop the trigger or drop and recreate the pg_repack extension altogether to remove all the temporary objects left over.
350+
CREATE TABLE trg3 (id integer PRIMARY KEY);
351+
CREATE TRIGGER z_repack_trigges BEFORE UPDATE ON trg3 FOR EACH ROW EXECUTE PROCEDURE trgtest();
352+
\! pg_repack --dbname=contrib_regression --table=trg3
353+
INFO: repacking table "trg3"
354+
WARNING: trigger "z_repack_trigges" conflicting on table "trg3"
355+
DETAIL: The trigger "z_repack_trigger" must be the last of the BEFORE triggers to fire on the table (triggers fire in alphabetical order). Please rename the trigger so that it sorts before "z_repack_trigger": you can use "ALTER TRIGGER z_repack_trigges ON trg3 RENAME TO newname".
356+
CREATE TABLE trg4 (id integer PRIMARY KEY);
357+
CREATE TRIGGER zzzzzz AFTER UPDATE ON trg4 FOR EACH ROW EXECUTE PROCEDURE trgtest();
358+
\! pg_repack --dbname=contrib_regression --table=trg4
359+
INFO: repacking table "trg4"
360+
--
361+
-- Dry run
362+
--
363+
\! pg_repack --dbname=contrib_regression --table=tbl_cluster --dry-run
364+
INFO: Dry run enabled, not executing repack
365+
INFO: repacking table "tbl_cluster"
366+
-- Test --schema
367+
--
368+
CREATE SCHEMA test_schema1;
369+
CREATE TABLE test_schema1.tbl1 (id INTEGER PRIMARY KEY);
370+
CREATE TABLE test_schema1.tbl2 (id INTEGER PRIMARY KEY);
371+
CREATE SCHEMA test_schema2;
372+
CREATE TABLE test_schema2.tbl1 (id INTEGER PRIMARY KEY);
373+
CREATE TABLE test_schema2.tbl2 (id INTEGER PRIMARY KEY);
374+
-- => OK
375+
\! pg_repack --dbname=contrib_regression --schema=test_schema1
376+
INFO: repacking table "test_schema1.tbl1"
377+
INFO: repacking table "test_schema1.tbl2"
378+
-- => OK
379+
\! pg_repack --dbname=contrib_regression --schema=test_schema1 --schema=test_schema2
380+
INFO: repacking table "test_schema1.tbl1"
381+
INFO: repacking table "test_schema1.tbl2"
382+
INFO: repacking table "test_schema2.tbl1"
383+
INFO: repacking table "test_schema2.tbl2"
384+
-- => ERROR
385+
\! pg_repack --dbname=contrib_regression --schema=test_schema1 --table=tbl1
386+
ERROR: cannot repack specific table(s) in schema, use schema.table notation instead
387+
-- => ERROR
388+
\! pg_repack --dbname=contrib_regression --all --schema=test_schema1
389+
ERROR: cannot repack specific schema(s) in all databases

0 commit comments

Comments
 (0)