Skip to content

Commit 20dea46

Browse files
committed
Merge remote-tracking branch 'piro/master'
2 parents c55c613 + 98d3047 commit 20dea46

20 files changed

+698
-264
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# Global excludes across all subdirectories
22
*.o
33
*.so
4+
bin/regression.diffs
5+
bin/regression.out

META.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "pg_repack",
33
"abstract": "PostgreSQL module for data reorganization",
44
"description": "Reorganize tables in PostgreSQL databases with minimal locks",
5-
"version": "1.2dev0",
5+
"version": "1.2dev1",
66
"maintainer": [
77
"Josh Kupershmidt <schmiddy@gmail.com>",
88
"Daniele Varrazzo <daniele.varrazzo@gmail.com>"
@@ -13,7 +13,7 @@
1313
"provides": {
1414
"pg_repack": {
1515
"file": "lib/pg_repack.sql",
16-
"version": "1.2dev0",
16+
"version": "1.2dev1",
1717
"abstract": "Reorganize tables in PostgreSQL databases with minimal locks"
1818
}
1919
},

Makefile

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,25 @@
66
# Portions Copyright (c) 2012, The Reorg Development Team
77
#
88

9-
USE_PGXS = 1
10-
PG_CONFIG = pg_config
11-
PGXS := $(shell $(PG_CONFIG) --pgxs)
12-
include $(PGXS)
13-
14-
SUBDIRS = bin lib
9+
PG_CONFIG ?= pg_config
1510

1611
# Pull out the version number from pg_config
17-
VERSION = $(shell $(PG_CONFIG) --version | awk '{print $$2}')
12+
VERSION := $(shell $(PG_CONFIG) --version | awk '{print $$2}')
13+
ifeq ("$(VERSION)","")
14+
$(error pg_config not found)
15+
endif
16+
17+
# version as a number, e.g. 9.1.4 -> 901
18+
INTVERSION := $(shell echo $$(($$(echo $(VERSION) | sed -E 's/([0-9]+)\.([0-9]+).*/\1*100+\2/'))))
1819

1920
# We support PostgreSQL 8.3 and later.
20-
ifneq ($(shell echo $(VERSION) | grep -E "^7\.|^8\.[012]"),)
21+
ifeq ($(shell echo $$(($(INTVERSION) < 803))),1)
2122
$(error pg_repack requires PostgreSQL 8.3 or later. This is $(VERSION))
2223
endif
2324

2425

26+
SUBDIRS = bin lib
27+
2528
all install installdirs uninstall distprep clean distclean maintainer-clean debug:
2629
@for dir in $(SUBDIRS); do \
2730
$(MAKE) -C $$dir $@ || exit; \

bin/Makefile

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,40 @@
55
# Portions Copyright (c) 2011, Itagaki Takahiro
66
# Portions Copyright (c) 2012, The Reorg Development Team
77
#
8+
9+
PG_CONFIG ?= pg_config
10+
11+
# version as a number, e.g. 9.1.4 -> 901
12+
VERSION := $(shell $(PG_CONFIG) --version | awk '{print $$2}')
13+
INTVERSION := $(shell echo $$(($$(echo $(VERSION) | sed -E 's/([0-9]+)\.([0-9]+).*/\1*100+\2/'))))
14+
815
SRCS = pg_repack.c pgut/pgut.c pgut/pgut-fe.c
916
OBJS = $(SRCS:.c=.o)
1017
PROGRAM = pg_repack
11-
REGRESS = init repack
1218

13-
EXTRA_CLEAN = sql/init-$(MAJORVERSION).sql sql/init.sql
19+
20+
#
21+
# Test suite
22+
#
23+
24+
ifeq ($(shell echo $$(($(INTVERSION) >= 901))),1)
25+
REGRESS := init-extension
26+
else
27+
REGRESS := init-legacy
28+
endif
29+
30+
# plpgsql not available by default on pg < 9.0
31+
ifeq ($(shell echo $$(($(INTVERSION) < 900))),1)
32+
REGRESS += plpgsql
33+
endif
34+
35+
REGRESS += repack tablespace
36+
37+
# This test depends on collate, not supported before 9.1
38+
ifeq ($(shell echo $$(($(INTVERSION) >= 901))),1)
39+
REGRESS += issue3
40+
endif
41+
1442

1543
# The version number of the program. It should be the same of the library.
1644
REPACK_VERSION = $(shell grep '"version":' ../META.json | head -1 \
@@ -33,25 +61,3 @@ include $(PGXS)
3361
LIBS := $(filter-out -lxml2, $(LIBS))
3462
LIBS := $(filter-out -lxslt, $(LIBS))
3563

36-
ifndef MAJORVERSION
37-
MAJORVERSION := $(basename $(VERSION))
38-
endif
39-
40-
sql/init.sql: sql/init-$(MAJORVERSION).sql
41-
cp sql/init-$(MAJORVERSION).sql sql/init.sql
42-
expected/init.out: expected/init-$(MAJORVERSION).out
43-
cp expected/init-$(MAJORVERSION).out expected/init.out
44-
sql/init-8.3.sql:
45-
cp sql/init-legacy.sql sql/init-8.3.sql
46-
sql/init-8.4.sql:
47-
cp sql/init-legacy.sql sql/init-8.4.sql
48-
sql/init-9.0.sql:
49-
cp sql/init-legacy.sql sql/init-9.0.sql
50-
sql/init-9.1.sql:
51-
cp sql/init-extension.sql sql/init-9.1.sql
52-
sql/init-9.2.sql:
53-
cp sql/init-extension.sql sql/init-9.2.sql
54-
sql/init-9.3.sql:
55-
cp sql/init-extension.sql sql/init-9.3.sql
56-
57-
installcheck: sql/init.sql

bin/expected/init-extension.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SET client_min_messages = warning;
2+
CREATE EXTENSION pg_repack;
3+
RESET client_min_messages;
File renamed without changes.

bin/expected/issue3.out

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
--
2+
-- pg_repack issue #3
3+
--
4+
CREATE TABLE issue3_1 (col1 int NOT NULL, col2 text NOT NULL);
5+
CREATE UNIQUE INDEX issue3_1_idx ON issue3_1 (col1, col2 DESC);
6+
SELECT repack.get_order_by('issue3_1_idx'::regclass::oid, 'issue3_1'::regclass::oid);
7+
get_order_by
8+
-----------------
9+
col1, col2 DESC
10+
(1 row)
11+
12+
\! pg_repack --dbname=contrib_regression --table=issue3_1
13+
INFO: repacking table "issue3_1"
14+
CREATE TABLE issue3_2 (col1 int NOT NULL, col2 text NOT NULL);
15+
CREATE UNIQUE INDEX issue3_2_idx ON issue3_2 (col1 DESC, col2 text_pattern_ops);
16+
SELECT repack.get_order_by('issue3_2_idx'::regclass::oid, 'issue3_2'::regclass::oid);
17+
get_order_by
18+
---------------------------
19+
col1 DESC, col2 USING ~<~
20+
(1 row)
21+
22+
\! pg_repack --dbname=contrib_regression --table=issue3_2
23+
INFO: repacking table "issue3_2"
24+
CREATE TABLE issue3_3 (col1 int NOT NULL, col2 text NOT NULL);
25+
CREATE UNIQUE INDEX issue3_3_idx ON issue3_3 (col1 DESC, col2 DESC);
26+
SELECT repack.get_order_by('issue3_3_idx'::regclass::oid, 'issue3_3'::regclass::oid);
27+
get_order_by
28+
----------------------
29+
col1 DESC, col2 DESC
30+
(1 row)
31+
32+
\! pg_repack --dbname=contrib_regression --table=issue3_3
33+
INFO: repacking table "issue3_3"
34+
CREATE TABLE issue3_4 (col1 int NOT NULL, col2 text NOT NULL);
35+
CREATE UNIQUE INDEX issue3_4_idx ON issue3_4 (col1 NULLS FIRST, col2 text_pattern_ops DESC NULLS LAST);
36+
SELECT repack.get_order_by('issue3_4_idx'::regclass::oid, 'issue3_4'::regclass::oid);
37+
get_order_by
38+
--------------------------------------------------
39+
col1 NULLS FIRST, col2 DESC USING ~<~ NULLS LAST
40+
(1 row)
41+
42+
\! pg_repack --dbname=contrib_regression --table=issue3_4
43+
INFO: repacking table "issue3_4"
44+
CREATE TABLE issue3_5 (col1 int NOT NULL, col2 text NOT NULL);
45+
CREATE UNIQUE INDEX issue3_5_idx ON issue3_5 (col1 DESC NULLS FIRST, col2 COLLATE "POSIX" DESC);
46+
SELECT repack.get_order_by('issue3_5_idx'::regclass::oid, 'issue3_5'::regclass::oid);
47+
get_order_by
48+
--------------------------------------
49+
col1 DESC, col2 COLLATE "POSIX" DESC
50+
(1 row)
51+
52+
\! pg_repack --dbname=contrib_regression --table=issue3_5
53+
INFO: repacking table "issue3_5"

bin/expected/plpgsql.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CREATE LANGUAGE plpgsql;

bin/expected/repack.out

Lines changed: 43 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,20 @@ SELECT * FROM tbl_with_dropped_toast;
114114
--
115115
-- do repack
116116
--
117-
\! pg_repack --dbname=contrib_regression --no-order
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"
118121
WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON tbl_badindex USING btree (n)
119122
\! pg_repack --dbname=contrib_regression
120-
\! pg_repack --dbname=contrib_regression --table=tbl_cluster
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"
121131
--
122132
-- after
123133
--
@@ -301,64 +311,44 @@ CREATE TABLE tbl_nn_uk (col1 int NOT NULL, col2 int NOT NULL, UNIQUE(col1, col2)
301311
CREATE TABLE tbl_pk_uk (col1 int NOT NULL, col2 int NOT NULL, PRIMARY KEY(col1, col2), UNIQUE(col2, col1));
302312
CREATE TABLE tbl_nn_puk (col1 int NOT NULL, col2 int NOT NULL);
303313
CREATE UNIQUE INDEX tbl_nn_puk_pcol1_idx ON tbl_nn_puk(col1) WHERE col1 < 10;
304-
\! pg_repack --dbname=contrib_regression --no-order --table=tbl_nn
314+
\! pg_repack --dbname=contrib_regression --table=tbl_nn
305315
WARNING: relation "tbl_nn" must have a primary key or not-null unique keys
306316
-- => WARNING
307-
\! pg_repack --dbname=contrib_regression --no-order --table=tbl_uk
317+
\! pg_repack --dbname=contrib_regression --table=tbl_uk
308318
WARNING: relation "tbl_uk" must have a primary key or not-null unique keys
309319
-- => WARNING
310-
\! pg_repack --dbname=contrib_regression --no-order --table=tbl_nn_uk
320+
\! pg_repack --dbname=contrib_regression --table=tbl_nn_uk
321+
INFO: repacking table "tbl_nn_uk"
311322
-- => OK
312-
\! pg_repack --dbname=contrib_regression --no-order --table=tbl_pk_uk
323+
\! pg_repack --dbname=contrib_regression --table=tbl_pk_uk
324+
INFO: repacking table "tbl_pk_uk"
313325
-- => OK
314-
\! pg_repack --dbname=contrib_regression --no-order --table=tbl_nn_puk
326+
\! pg_repack --dbname=contrib_regression --table=tbl_nn_puk
315327
WARNING: relation "tbl_nn_puk" must have a primary key or not-null unique keys
316328
-- => WARNING
317329
--
318-
-- pg_repack issue #3
330+
-- Triggers handling
319331
--
320-
CREATE TABLE issue3_1 (col1 int NOT NULL, col2 text NOT NULL);
321-
CREATE UNIQUE INDEX issue3_1_idx ON issue3_1 (col1, col2 DESC);
322-
SELECT repack.get_order_by('issue3_1_idx'::regclass::oid, 'issue3_1'::regclass::oid);
323-
get_order_by
324-
-----------------
325-
col1, col2 DESC
326-
(1 row)
327-
328-
\! pg_repack --dbname=contrib_regression --no-order --table=issue3_1
329-
CREATE TABLE issue3_2 (col1 int NOT NULL, col2 text NOT NULL);
330-
CREATE UNIQUE INDEX issue3_2_idx ON issue3_2 (col1 DESC, col2 text_pattern_ops);
331-
SELECT repack.get_order_by('issue3_2_idx'::regclass::oid, 'issue3_2'::regclass::oid);
332-
get_order_by
333-
---------------------------
334-
col1 DESC, col2 USING ~<~
335-
(1 row)
336-
337-
\! pg_repack --dbname=contrib_regression --no-order --table=issue3_2
338-
CREATE TABLE issue3_3 (col1 int NOT NULL, col2 text NOT NULL);
339-
CREATE UNIQUE INDEX issue3_3_idx ON issue3_3 (col1 DESC, col2 DESC);
340-
SELECT repack.get_order_by('issue3_3_idx'::regclass::oid, 'issue3_3'::regclass::oid);
341-
get_order_by
342-
----------------------
343-
col1 DESC, col2 DESC
344-
(1 row)
345-
346-
\! pg_repack --dbname=contrib_regression --no-order --table=issue3_3
347-
CREATE TABLE issue3_4 (col1 int NOT NULL, col2 text NOT NULL);
348-
CREATE UNIQUE INDEX issue3_4_idx ON issue3_4 (col1 NULLS FIRST, col2 text_pattern_ops DESC NULLS LAST);
349-
SELECT repack.get_order_by('issue3_4_idx'::regclass::oid, 'issue3_4'::regclass::oid);
350-
get_order_by
351-
--------------------------------------------------
352-
col1 NULLS FIRST, col2 DESC USING ~<~ NULLS LAST
353-
(1 row)
354-
355-
\! pg_repack --dbname=contrib_regression --no-order --table=issue3_4
356-
CREATE TABLE issue3_5 (col1 int NOT NULL, col2 text NOT NULL);
357-
CREATE UNIQUE INDEX issue3_5_idx ON issue3_5 (col1 DESC NULLS FIRST, col2 COLLATE "POSIX" DESC);
358-
SELECT repack.get_order_by('issue3_5_idx'::regclass::oid, 'issue3_5'::regclass::oid);
359-
get_order_by
360-
--------------------------------------
361-
col1 DESC, col2 COLLATE "POSIX" DESC
362-
(1 row)
363-
364-
\! pg_repack --dbname=contrib_regression --no-order --table=issue3_5
332+
CREATE FUNCTION trgtest() RETURNS trigger AS
333+
$$BEGIN RETURN NEW; END$$
334+
LANGUAGE plpgsql;
335+
CREATE TABLE trg1 (id integer PRIMARY KEY);
336+
CREATE TRIGGER z_repack_triggeq BEFORE UPDATE ON trg1 FOR EACH ROW EXECUTE PROCEDURE trgtest();
337+
\! pg_repack --dbname=contrib_regression --table=trg1
338+
INFO: repacking table "trg1"
339+
CREATE TABLE trg2 (id integer PRIMARY KEY);
340+
CREATE TRIGGER z_repack_trigger BEFORE UPDATE ON trg2 FOR EACH ROW EXECUTE PROCEDURE trgtest();
341+
\! pg_repack --dbname=contrib_regression --table=trg2
342+
INFO: repacking table "trg2"
343+
WARNING: the table "trg2" has already a trigger called "z_repack_trigger"
344+
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.
345+
CREATE TABLE trg3 (id integer PRIMARY KEY);
346+
CREATE TRIGGER z_repack_trigges BEFORE UPDATE ON trg3 FOR EACH ROW EXECUTE PROCEDURE trgtest();
347+
\! pg_repack --dbname=contrib_regression --table=trg3
348+
INFO: repacking table "trg3"
349+
WARNING: trigger "z_repack_trigges" conflicting on table "trg3"
350+
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".
351+
CREATE TABLE trg4 (id integer PRIMARY KEY);
352+
CREATE TRIGGER zzzzzz AFTER UPDATE ON trg4 FOR EACH ROW EXECUTE PROCEDURE trgtest();
353+
\! pg_repack --dbname=contrib_regression --table=trg4
354+
INFO: repacking table "trg4"

0 commit comments

Comments
 (0)