]> granicus.if.org Git - postgresql/commit
Check that partitions are not in use when dropping constraints
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Tue, 23 Jul 2019 21:22:15 +0000 (17:22 -0400)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Tue, 23 Jul 2019 21:22:15 +0000 (17:22 -0400)
commit3ffe655c0af03cb4d5aab18da2aaa7022d207bf3
tree2887a07935f1b558bf3d1daf3c1e56811ba101d6
parent79e573fa4986be54c30d1313709c26c2a34488c8
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
src/backend/commands/tablecmds.c
src/test/regress/expected/foreign_key.out
src/test/regress/sql/foreign_key.sql