summaryrefslogtreecommitdiff
path: root/src/test/regress/expected/foreign_key.out
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2019-07-23 17:22:15 -0400
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2019-07-23 17:22:15 -0400
commit5562272a4229cfa57354aa203cffd36b4e7f70cb (patch)
treeaa0fc6f63b37283c334dd4c4b8308ab77bdf677b /src/test/regress/expected/foreign_key.out
parent24f62e93f314c107b4fa679869e5ba9adb2d545f (diff)
downloadpostgresql-5562272a4229cfa57354aa203cffd36b4e7f70cb.tar.gz
Check that partitions are not in use when dropping constraints
If the user creates a deferred constraint in a partition, and in a transaction they cause the constraint's trigger execution to be deferred until commit time *and* drop the constraint, then when commit time comes the queued trigger will fail to run because the trigger object will have been dropped. This is explained because when a constraint gets dropped in a partitioned table, the recursion to drop the ones in partitions is done by the dependency mechanism, not by ALTER TABLE traversing the recursion tree as in all other cases. In the non-partitioned case, this problem is avoided by checking that the table is not "in use" by alter-table; other alter-table subcommands that recurse to partitions do that check for each partition. But the dependency mechanism doesn't have a way to do that. Fix the problem by applying the same check to all partitions during ALTER TABLE's "prep" phase, which correctly raises the necessary error. Reported-by: Rajkumar Raghuwanshi <rajkumar.raghuwanshi@enterprisedb.com> Discussion: https://postgr.es/m/CAKcux6nZiO9-eEpr1ZD84bT1mBoVmeZkfont8iSpcmYrjhGWgA@mail.gmail.com
Diffstat (limited to 'src/test/regress/expected/foreign_key.out')
-rw-r--r--src/test/regress/expected/foreign_key.out15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/test/regress/expected/foreign_key.out b/src/test/regress/expected/foreign_key.out
index 58f6058e70..f0ecf4b270 100644
--- a/src/test/regress/expected/foreign_key.out
+++ b/src/test/regress/expected/foreign_key.out
@@ -2379,3 +2379,18 @@ DROP SCHEMA fkpart7 CASCADE;
NOTICE: drop cascades to 2 other objects
DETAIL: drop cascades to table fkpart7.pkpart
drop cascades to table fkpart7.fk
+-- ensure we check partitions are "not used" when dropping constraints
+CREATE SCHEMA fkpart8
+ CREATE TABLE tbl1(f1 int PRIMARY KEY)
+ CREATE TABLE tbl2(f1 int REFERENCES tbl1 DEFERRABLE INITIALLY DEFERRED) PARTITION BY RANGE(f1)
+ CREATE TABLE tbl2_p1 PARTITION OF tbl2 FOR VALUES FROM (minvalue) TO (maxvalue);
+INSERT INTO fkpart8.tbl1 VALUES(1);
+BEGIN;
+INSERT INTO fkpart8.tbl2 VALUES(1);
+ALTER TABLE fkpart8.tbl2 DROP CONSTRAINT tbl2_f1_fkey;
+ERROR: cannot ALTER TABLE "tbl2_p1" because it has pending trigger events
+COMMIT;
+DROP SCHEMA fkpart8 CASCADE;
+NOTICE: drop cascades to 2 other objects
+DETAIL: drop cascades to table fkpart8.tbl1
+drop cascades to table fkpart8.tbl2