diff options
| author | Alvaro Herrera | 2024-04-15 13:07:47 +0000 |
|---|---|---|
| committer | Alvaro Herrera | 2024-04-15 13:07:47 +0000 |
| commit | cee8db3f680b737b64d747530b48d30828cf4790 (patch) | |
| tree | f45fbe7ffe98414d9e4e4b8348597f3bff73ca38 /src/test | |
| parent | 9dfcac8e15acc3b4d4d5bc02383a56ccb07229fe (diff) | |
ATTACH PARTITION: Don't match a PK with a UNIQUE constraint
When matching constraints in AttachPartitionEnsureIndexes() we weren't
testing the constraint type, which could make a UNIQUE key lacking a
not-null constraint incorrectly satisfy a primary key requirement. Fix
this by testing that the constraint types match. (Other possible
mismatches are verified by comparing index properties.)
Discussion: https://postgr.es/m/202402051447.wimb4xmtiiyb@alvherre.pgsql
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/regress/expected/constraints.out | 16 | ||||
| -rw-r--r-- | src/test/regress/sql/constraints.sql | 7 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/test/regress/expected/constraints.out b/src/test/regress/expected/constraints.out index 483681ef2c6..51157181c64 100644 --- a/src/test/regress/expected/constraints.out +++ b/src/test/regress/expected/constraints.out @@ -1006,6 +1006,22 @@ Inherits: cnn_grandchild, ALTER TABLE cnn_parent DROP CONSTRAINT cnn_parent_pkey; ERROR: constraint "cnn_parent_pkey" of relation "cnn_parent" does not exist -- keeps these tables around, for pg_upgrade testing +-- A primary key shouldn't attach to a unique constraint +create table cnn2_parted (a int primary key) partition by list (a); +create table cnn2_part1 (a int unique); +alter table cnn2_parted attach partition cnn2_part1 for values in (1); +\d+ cnn2_part1 + Table "public.cnn2_part1" + Column | Type | Collation | Nullable | Default | Storage | Stats target | Description +--------+---------+-----------+----------+---------+---------+--------------+------------- + a | integer | | not null | | plain | | +Partition of: cnn2_parted FOR VALUES IN (1) +Partition constraint: ((a IS NOT NULL) AND (a = 1)) +Indexes: + "cnn2_part1_pkey" PRIMARY KEY, btree (a) + "cnn2_part1_a_key" UNIQUE CONSTRAINT, btree (a) + +drop table cnn2_parted; -- ensure columns in partitions are marked not-null create table cnn2_parted(a int primary key) partition by list (a); create table cnn2_part1(a int); diff --git a/src/test/regress/sql/constraints.sql b/src/test/regress/sql/constraints.sql index 7c95f6c2aa7..2efb63e9d8f 100644 --- a/src/test/regress/sql/constraints.sql +++ b/src/test/regress/sql/constraints.sql @@ -657,6 +657,13 @@ ALTER TABLE cnn_parent ADD PRIMARY KEY USING INDEX b_uq; ALTER TABLE cnn_parent DROP CONSTRAINT cnn_parent_pkey; -- keeps these tables around, for pg_upgrade testing +-- A primary key shouldn't attach to a unique constraint +create table cnn2_parted (a int primary key) partition by list (a); +create table cnn2_part1 (a int unique); +alter table cnn2_parted attach partition cnn2_part1 for values in (1); +\d+ cnn2_part1 +drop table cnn2_parted; + -- ensure columns in partitions are marked not-null create table cnn2_parted(a int primary key) partition by list (a); create table cnn2_part1(a int); |
