Move regression tests from ./bin/ to ./regress/
This commit is contained in:
3
regress/sql/init-extension.sql
Normal file
3
regress/sql/init-extension.sql
Normal file
@ -0,0 +1,3 @@
|
||||
SET client_min_messages = warning;
|
||||
CREATE EXTENSION pg_repack;
|
||||
RESET client_min_messages;
|
5
regress/sql/init-legacy.sql
Normal file
5
regress/sql/init-legacy.sql
Normal file
@ -0,0 +1,5 @@
|
||||
SET client_min_messages = warning;
|
||||
\set ECHO none
|
||||
\i ../lib/pg_repack.sql
|
||||
\set ECHO all
|
||||
RESET client_min_messages;
|
27
regress/sql/issue3.sql
Normal file
27
regress/sql/issue3.sql
Normal file
@ -0,0 +1,27 @@
|
||||
--
|
||||
-- pg_repack issue #3
|
||||
--
|
||||
CREATE TABLE issue3_1 (col1 int NOT NULL, col2 text NOT NULL);
|
||||
CREATE UNIQUE INDEX issue3_1_idx ON issue3_1 (col1, col2 DESC);
|
||||
SELECT repack.get_order_by('issue3_1_idx'::regclass::oid, 'issue3_1'::regclass::oid);
|
||||
\! pg_repack --dbname=contrib_regression --table=issue3_1
|
||||
|
||||
CREATE TABLE issue3_2 (col1 int NOT NULL, col2 text NOT NULL);
|
||||
CREATE UNIQUE INDEX issue3_2_idx ON issue3_2 (col1 DESC, col2 text_pattern_ops);
|
||||
SELECT repack.get_order_by('issue3_2_idx'::regclass::oid, 'issue3_2'::regclass::oid);
|
||||
\! pg_repack --dbname=contrib_regression --table=issue3_2
|
||||
|
||||
CREATE TABLE issue3_3 (col1 int NOT NULL, col2 text NOT NULL);
|
||||
CREATE UNIQUE INDEX issue3_3_idx ON issue3_3 (col1 DESC, col2 DESC);
|
||||
SELECT repack.get_order_by('issue3_3_idx'::regclass::oid, 'issue3_3'::regclass::oid);
|
||||
\! pg_repack --dbname=contrib_regression --table=issue3_3
|
||||
|
||||
CREATE TABLE issue3_4 (col1 int NOT NULL, col2 text NOT NULL);
|
||||
CREATE UNIQUE INDEX issue3_4_idx ON issue3_4 (col1 NULLS FIRST, col2 text_pattern_ops DESC NULLS LAST);
|
||||
SELECT repack.get_order_by('issue3_4_idx'::regclass::oid, 'issue3_4'::regclass::oid);
|
||||
\! pg_repack --dbname=contrib_regression --table=issue3_4
|
||||
|
||||
CREATE TABLE issue3_5 (col1 int NOT NULL, col2 text NOT NULL);
|
||||
CREATE UNIQUE INDEX issue3_5_idx ON issue3_5 (col1 DESC NULLS FIRST, col2 COLLATE "POSIX" DESC);
|
||||
SELECT repack.get_order_by('issue3_5_idx'::regclass::oid, 'issue3_5'::regclass::oid);
|
||||
\! pg_repack --dbname=contrib_regression --table=issue3_5
|
1
regress/sql/plpgsql.sql
Normal file
1
regress/sql/plpgsql.sql
Normal file
@ -0,0 +1 @@
|
||||
CREATE LANGUAGE plpgsql;
|
208
regress/sql/repack.sql
Normal file
208
regress/sql/repack.sql
Normal file
@ -0,0 +1,208 @@
|
||||
SET client_min_messages = warning;
|
||||
--
|
||||
-- create table.
|
||||
--
|
||||
CREATE TABLE tbl_cluster (
|
||||
col1 int,
|
||||
"time" timestamp,
|
||||
","")" text,
|
||||
PRIMARY KEY (","")", col1) WITH (fillfactor = 75)
|
||||
) WITH (fillfactor = 70);
|
||||
|
||||
CREATE INDEX ","") cluster" ON tbl_cluster ("time", length(","")"), ","")" text_pattern_ops) WITH (fillfactor = 75);
|
||||
ALTER TABLE tbl_cluster CLUSTER ON ","") cluster";
|
||||
|
||||
CREATE TABLE tbl_only_pkey (
|
||||
col1 int PRIMARY KEY,
|
||||
","")" text
|
||||
);
|
||||
|
||||
CREATE TABLE tbl_only_ckey (
|
||||
col1 int,
|
||||
col2 timestamp,
|
||||
","")" text
|
||||
) WITH (fillfactor = 70);
|
||||
|
||||
CREATE INDEX cidx_only_ckey ON tbl_only_ckey (col2, ","")");
|
||||
ALTER TABLE tbl_only_ckey CLUSTER ON cidx_only_ckey;
|
||||
|
||||
CREATE TABLE tbl_gistkey (
|
||||
id integer PRIMARY KEY,
|
||||
c circle
|
||||
);
|
||||
|
||||
CREATE INDEX cidx_circle ON tbl_gistkey USING gist (c);
|
||||
ALTER TABLE tbl_gistkey CLUSTER ON cidx_circle;
|
||||
|
||||
CREATE TABLE tbl_with_dropped_column (
|
||||
d1 text,
|
||||
c1 text,
|
||||
id integer PRIMARY KEY,
|
||||
d2 text,
|
||||
c2 text,
|
||||
d3 text
|
||||
);
|
||||
ALTER INDEX tbl_with_dropped_column_pkey SET (fillfactor = 75);
|
||||
ALTER TABLE tbl_with_dropped_column CLUSTER ON tbl_with_dropped_column_pkey;
|
||||
CREATE INDEX idx_c1c2 ON tbl_with_dropped_column (c1, c2) WITH (fillfactor = 75);
|
||||
CREATE INDEX idx_c2c1 ON tbl_with_dropped_column (c2, c1);
|
||||
|
||||
CREATE TABLE tbl_with_dropped_toast (
|
||||
i integer,
|
||||
j integer,
|
||||
t text,
|
||||
PRIMARY KEY (i, j)
|
||||
);
|
||||
ALTER TABLE tbl_with_dropped_toast CLUSTER ON tbl_with_dropped_toast_pkey;
|
||||
|
||||
CREATE TABLE tbl_badindex (
|
||||
id integer PRIMARY KEY,
|
||||
n integer
|
||||
);
|
||||
|
||||
CREATE TABLE tbl_idxopts (
|
||||
i integer PRIMARY KEY,
|
||||
t text
|
||||
);
|
||||
CREATE INDEX idxopts_t ON tbl_idxopts (t DESC NULLS LAST) WHERE (t != 'aaa');
|
||||
|
||||
--
|
||||
-- insert data
|
||||
--
|
||||
|
||||
INSERT INTO tbl_cluster VALUES(1, '2008-12-31 10:00:00', 'admin');
|
||||
INSERT INTO tbl_cluster VALUES(2, '2008-01-01 00:00:00', 'king');
|
||||
INSERT INTO tbl_cluster VALUES(3, '2008-03-04 12:00:00', 'joker');
|
||||
INSERT INTO tbl_cluster VALUES(4, '2008-03-05 15:00:00', 'queen');
|
||||
INSERT INTO tbl_cluster VALUES(5, '2008-01-01 00:30:00', sqrt(2::numeric(1000,999))::text || sqrt(3::numeric(1000,999))::text);
|
||||
|
||||
INSERT INTO tbl_only_pkey VALUES(1, 'abc');
|
||||
INSERT INTO tbl_only_pkey VALUES(2, 'def');
|
||||
|
||||
INSERT INTO tbl_only_ckey VALUES(1, '2008-01-01 00:00:00', 'abc');
|
||||
INSERT INTO tbl_only_ckey VALUES(2, '2008-02-01 00:00:00', 'def');
|
||||
|
||||
INSERT INTO tbl_gistkey VALUES(1, '<(1,2),3>');
|
||||
INSERT INTO tbl_gistkey VALUES(2, '<(4,5),6>');
|
||||
|
||||
INSERT INTO tbl_with_dropped_column VALUES('d1', 'c1', 2, 'd2', 'c2', 'd3');
|
||||
INSERT INTO tbl_with_dropped_column VALUES('d1', 'c1', 1, 'd2', 'c2', 'd3');
|
||||
ALTER TABLE tbl_with_dropped_column DROP COLUMN d1;
|
||||
ALTER TABLE tbl_with_dropped_column DROP COLUMN d2;
|
||||
ALTER TABLE tbl_with_dropped_column DROP COLUMN d3;
|
||||
ALTER TABLE tbl_with_dropped_column ADD COLUMN c3 text;
|
||||
CREATE VIEW view_for_dropped_column AS
|
||||
SELECT * FROM tbl_with_dropped_column;
|
||||
|
||||
INSERT INTO tbl_with_dropped_toast VALUES(1, 10, 'abc');
|
||||
INSERT INTO tbl_with_dropped_toast VALUES(2, 20, sqrt(2::numeric(1000,999))::text || sqrt(3::numeric(1000,999))::text);
|
||||
ALTER TABLE tbl_with_dropped_toast DROP COLUMN t;
|
||||
|
||||
INSERT INTO tbl_badindex VALUES(1, 10);
|
||||
INSERT INTO tbl_badindex VALUES(2, 10);
|
||||
|
||||
-- This will fail. Silence the message as it's different across PG versions.
|
||||
SET client_min_messages = fatal;
|
||||
CREATE UNIQUE INDEX CONCURRENTLY idx_badindex_n ON tbl_badindex (n);
|
||||
SET client_min_messages = warning;
|
||||
|
||||
INSERT INTO tbl_idxopts VALUES (0, 'abc'), (1, 'aaa'), (2, NULL), (3, 'bbb');
|
||||
|
||||
--
|
||||
-- before
|
||||
--
|
||||
|
||||
SELECT * FROM tbl_with_dropped_column;
|
||||
SELECT * FROM view_for_dropped_column;
|
||||
SELECT * FROM tbl_with_dropped_toast;
|
||||
|
||||
--
|
||||
-- do repack
|
||||
--
|
||||
|
||||
\! pg_repack --dbname=contrib_regression --table=tbl_cluster
|
||||
\! pg_repack --dbname=contrib_regression --table=tbl_badindex
|
||||
\! pg_repack --dbname=contrib_regression
|
||||
|
||||
--
|
||||
-- after
|
||||
--
|
||||
|
||||
\d tbl_cluster
|
||||
\d tbl_gistkey
|
||||
\d tbl_only_ckey
|
||||
\d tbl_only_pkey
|
||||
\d tbl_with_dropped_column
|
||||
\d tbl_with_dropped_toast
|
||||
\d tbl_idxopts
|
||||
|
||||
SELECT col1, to_char("time", 'YYYY-MM-DD HH24:MI:SS'), ","")" FROM tbl_cluster;
|
||||
SELECT * FROM tbl_only_ckey ORDER BY 1;
|
||||
SELECT * FROM tbl_only_pkey ORDER BY 1;
|
||||
SELECT * FROM tbl_gistkey ORDER BY 1;
|
||||
|
||||
SET enable_seqscan = on;
|
||||
SET enable_indexscan = off;
|
||||
SELECT * FROM tbl_with_dropped_column;
|
||||
SELECT * FROM view_for_dropped_column;
|
||||
SELECT * FROM tbl_with_dropped_toast;
|
||||
SET enable_seqscan = off;
|
||||
SET enable_indexscan = on;
|
||||
SELECT * FROM tbl_with_dropped_column;
|
||||
SELECT * FROM view_for_dropped_column;
|
||||
SELECT * FROM tbl_with_dropped_toast;
|
||||
RESET enable_seqscan;
|
||||
RESET enable_indexscan;
|
||||
|
||||
--
|
||||
-- check broken links or orphan toast relations
|
||||
--
|
||||
SELECT oid, relname
|
||||
FROM pg_class
|
||||
WHERE relkind = 't'
|
||||
AND oid NOT IN (SELECT reltoastrelid FROM pg_class WHERE relkind = 'r');
|
||||
|
||||
SELECT oid, relname
|
||||
FROM pg_class
|
||||
WHERE relkind = 'r'
|
||||
AND reltoastrelid <> 0
|
||||
AND reltoastrelid NOT IN (SELECT oid FROM pg_class WHERE relkind = 't');
|
||||
|
||||
--
|
||||
-- NOT NULL UNIQUE
|
||||
--
|
||||
CREATE TABLE tbl_nn (col1 int NOT NULL, col2 int NOT NULL);
|
||||
CREATE TABLE tbl_uk (col1 int NOT NULL, col2 int , UNIQUE(col1, col2));
|
||||
CREATE TABLE tbl_nn_uk (col1 int NOT NULL, col2 int NOT NULL, UNIQUE(col1, col2));
|
||||
CREATE TABLE tbl_pk_uk (col1 int NOT NULL, col2 int NOT NULL, PRIMARY KEY(col1, col2), UNIQUE(col2, col1));
|
||||
CREATE TABLE tbl_nn_puk (col1 int NOT NULL, col2 int NOT NULL);
|
||||
CREATE UNIQUE INDEX tbl_nn_puk_pcol1_idx ON tbl_nn_puk(col1) WHERE col1 < 10;
|
||||
\! pg_repack --dbname=contrib_regression --table=tbl_nn
|
||||
-- => WARNING
|
||||
\! pg_repack --dbname=contrib_regression --table=tbl_uk
|
||||
-- => WARNING
|
||||
\! pg_repack --dbname=contrib_regression --table=tbl_nn_uk
|
||||
-- => OK
|
||||
\! pg_repack --dbname=contrib_regression --table=tbl_pk_uk
|
||||
-- => OK
|
||||
\! pg_repack --dbname=contrib_regression --table=tbl_nn_puk
|
||||
-- => WARNING
|
||||
|
||||
--
|
||||
-- Triggers handling
|
||||
--
|
||||
CREATE FUNCTION trgtest() RETURNS trigger AS
|
||||
$$BEGIN RETURN NEW; END$$
|
||||
LANGUAGE plpgsql;
|
||||
CREATE TABLE trg1 (id integer PRIMARY KEY);
|
||||
CREATE TRIGGER z_repack_triggeq BEFORE UPDATE ON trg1 FOR EACH ROW EXECUTE PROCEDURE trgtest();
|
||||
\! pg_repack --dbname=contrib_regression --table=trg1
|
||||
CREATE TABLE trg2 (id integer PRIMARY KEY);
|
||||
CREATE TRIGGER z_repack_trigger BEFORE UPDATE ON trg2 FOR EACH ROW EXECUTE PROCEDURE trgtest();
|
||||
\! pg_repack --dbname=contrib_regression --table=trg2
|
||||
CREATE TABLE trg3 (id integer PRIMARY KEY);
|
||||
CREATE TRIGGER z_repack_trigges BEFORE UPDATE ON trg3 FOR EACH ROW EXECUTE PROCEDURE trgtest();
|
||||
\! pg_repack --dbname=contrib_regression --table=trg3
|
||||
CREATE TABLE trg4 (id integer PRIMARY KEY);
|
||||
CREATE TRIGGER zzzzzz AFTER UPDATE ON trg4 FOR EACH ROW EXECUTE PROCEDURE trgtest();
|
||||
\! pg_repack --dbname=contrib_regression --table=trg4
|
71
regress/sql/tablespace.sql
Normal file
71
regress/sql/tablespace.sql
Normal file
@ -0,0 +1,71 @@
|
||||
SET client_min_messages = warning;
|
||||
|
||||
--
|
||||
-- Tablespace features tests
|
||||
--
|
||||
-- Note: in order to pass this test you must create a tablespace called 'testts'
|
||||
--
|
||||
|
||||
SELECT spcname FROM pg_tablespace WHERE spcname = 'testts';
|
||||
-- If the query above failed you must create the 'testts' tablespace;
|
||||
|
||||
CREATE TABLE testts1 (id serial primary key, data text);
|
||||
CREATE INDEX testts1_partial_idx on testts1 (id) where (id > 0);
|
||||
CREATE INDEX testts1_with_idx on testts1 (id) with (fillfactor=80);
|
||||
INSERT INTO testts1 (data) values ('a');
|
||||
INSERT INTO testts1 (data) values ('b');
|
||||
INSERT INTO testts1 (data) values ('c');
|
||||
|
||||
-- check the indexes definitions
|
||||
SELECT regexp_replace(
|
||||
repack.repack_indexdef(indexrelid, 'testts1'::regclass, NULL),
|
||||
'_[0-9]+', '_OID', 'g')
|
||||
FROM pg_index i join pg_class c ON c.oid = indexrelid
|
||||
WHERE indrelid = 'testts1'::regclass ORDER BY relname;
|
||||
|
||||
SELECT regexp_replace(
|
||||
repack.repack_indexdef(indexrelid, 'testts1'::regclass, 'foo'),
|
||||
'_[0-9]+', '_OID', 'g')
|
||||
FROM pg_index i join pg_class c ON c.oid = indexrelid
|
||||
WHERE indrelid = 'testts1'::regclass ORDER BY relname;
|
||||
|
||||
-- can move the tablespace from default
|
||||
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace testts
|
||||
|
||||
SELECT relname, spcname
|
||||
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
||||
WHERE relname ~ '^testts1'
|
||||
ORDER BY relname;
|
||||
|
||||
SELECT * from testts1 order by id;
|
||||
|
||||
-- tablespace stays where it is
|
||||
\! pg_repack --dbname=contrib_regression --no-order --table=testts1
|
||||
|
||||
SELECT relname, spcname
|
||||
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
||||
WHERE relname ~ '^testts1'
|
||||
ORDER BY relname;
|
||||
|
||||
-- can move the ts back to default
|
||||
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 -s pg_default
|
||||
|
||||
SELECT relname, spcname
|
||||
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
||||
WHERE relname ~ '^testts1'
|
||||
ORDER BY relname;
|
||||
|
||||
-- can move the table together with the indexes
|
||||
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace testts --moveidx
|
||||
|
||||
SELECT relname, spcname
|
||||
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
||||
WHERE relname ~ '^testts1'
|
||||
ORDER BY relname;
|
||||
|
||||
-- can't specify --moveidx without --tablespace
|
||||
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --moveidx
|
||||
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 -S
|
||||
|
||||
-- not broken with order
|
||||
\! pg_repack --dbname=contrib_regression -o id --table=testts1 --tablespace pg_default --moveidx
|
Reference in New Issue
Block a user