1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-03 09:13:20 +03:00

Add missing CommandCounterIncrement

For commit b663b9436e I thought this was useless, but turns out not to
be for the case where a partitioned table has two identical foreign key
constraints which can both be matched by the same constraint in a
partition during attach.  This CCI makes the match search for the second
constraint in the parent ignore the constraint in the child that has
already been matched by the first constraint in the parent.

Reported-by: Alexander Lakhin <exclusion@gmail.com>
Discussion: https://postgr.es/m/c599253c-1ccd-4161-80fc-c9065e037a09@gmail.com
This commit is contained in:
Álvaro Herrera
2025-01-26 17:34:28 +01:00
parent d28cd3e7b2
commit 0a16c8326c
3 changed files with 31 additions and 10 deletions

View File

@@ -1491,6 +1491,17 @@ CREATE TABLE fk_partitioned_fk_6 (a int REFERENCES fk_partitioned_pk_6) PARTITIO
ALTER TABLE fk_partitioned_fk_6 ATTACH PARTITION fk_partitioned_pk_6 FOR VALUES IN (1);
DROP TABLE fk_partitioned_pk_6, fk_partitioned_fk_6;
-- Verify that attaching to a parent with two identical constraints work
CREATE TABLE fk_partitioned_pk_6 (a int PRIMARY KEY);
CREATE TABLE fk_partitioned_fk_6 (a int,
FOREIGN KEY (a) REFERENCES fk_partitioned_pk_6,
FOREIGN KEY (a) REFERENCES fk_partitioned_pk_6
) PARTITION BY LIST (a);
CREATE TABLE fk_partitioned_fk_6_1 PARTITION OF fk_partitioned_fk_6 FOR VALUES IN (1);
ALTER TABLE fk_partitioned_fk_6 DETACH PARTITION fk_partitioned_fk_6_1;
ALTER TABLE fk_partitioned_fk_6 ATTACH PARTITION fk_partitioned_fk_6_1 FOR VALUES IN (1);
DROP TABLE fk_partitioned_pk_6, fk_partitioned_fk_6;
-- This case is similar to above, but the referenced relation is one level
-- lower in the hierarchy. This one fails in a different way as the above,
-- because we don't bother to protect against this case explicitly. If the