Skip to content

Commit 44bf154

Browse files
committed
Don't choose a partial index as primary key
Fixes reorg/pg_reorg#22
1 parent ef2c7da commit 44bf154

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

bin/expected/repack.out

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ CREATE TABLE tbl_nn (col1 int NOT NULL, col2 int NOT NULL);
299299
CREATE TABLE tbl_uk (col1 int NOT NULL, col2 int , UNIQUE(col1, col2));
300300
CREATE TABLE tbl_nn_uk (col1 int NOT NULL, col2 int NOT NULL, UNIQUE(col1, col2));
301301
CREATE TABLE tbl_pk_uk (col1 int NOT NULL, col2 int NOT NULL, PRIMARY KEY(col1, col2), UNIQUE(col2, col1));
302+
CREATE TABLE tbl_nn_puk (col1 int NOT NULL, col2 int NOT NULL);
303+
CREATE UNIQUE INDEX tbl_nn_puk_pcol1_idx ON tbl_nn_puk(col1) WHERE col1 < 10;
302304
\! pg_repack --dbname=contrib_regression --no-order --table=tbl_nn
303305
ERROR: relation "tbl_nn" must have a primary key or not-null unique keys
304306
-- => ERROR
@@ -309,3 +311,6 @@ ERROR: relation "tbl_uk" must have a primary key or not-null unique keys
309311
-- => OK
310312
\! pg_repack --dbname=contrib_regression --no-order --table=tbl_pk_uk
311313
-- => OK
314+
\! pg_repack --dbname=contrib_regression --no-order --table=tbl_nn_puk
315+
ERROR: relation "tbl_nn_puk" must have a primary key or not-null unique keys
316+
-- => ERROR

bin/sql/repack.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ CREATE TABLE tbl_nn (col1 int NOT NULL, col2 int NOT NULL);
175175
CREATE TABLE tbl_uk (col1 int NOT NULL, col2 int , UNIQUE(col1, col2));
176176
CREATE TABLE tbl_nn_uk (col1 int NOT NULL, col2 int NOT NULL, UNIQUE(col1, col2));
177177
CREATE TABLE tbl_pk_uk (col1 int NOT NULL, col2 int NOT NULL, PRIMARY KEY(col1, col2), UNIQUE(col2, col1));
178+
CREATE TABLE tbl_nn_puk (col1 int NOT NULL, col2 int NOT NULL);
179+
CREATE UNIQUE INDEX tbl_nn_puk_pcol1_idx ON tbl_nn_puk(col1) WHERE col1 < 10;
178180
\! pg_repack --dbname=contrib_regression --no-order --table=tbl_nn
179181
-- => ERROR
180182
\! pg_repack --dbname=contrib_regression --no-order --table=tbl_uk
@@ -183,3 +185,5 @@ CREATE TABLE tbl_pk_uk (col1 int NOT NULL, col2 int NOT NULL, PRIMARY KEY(col1,
183185
-- => OK
184186
\! pg_repack --dbname=contrib_regression --no-order --table=tbl_pk_uk
185187
-- => OK
188+
\! pg_repack --dbname=contrib_regression --no-order --table=tbl_nn_puk
189+
-- => ERROR

lib/pg_repack.sql.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ CREATE VIEW repack.primary_keys AS
154154
FROM (SELECT indrelid, indexrelid FROM pg_index
155155
WHERE indisunique
156156
AND indisvalid
157+
AND indpred IS NULL
157158
AND 0 <> ALL(indkey)
158159
AND NOT EXISTS(
159160
SELECT 1 FROM pg_attribute

0 commit comments

Comments
 (0)