Create action triggers when partitions are detached
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Mon, 21 Jan 2019 22:59:07 +0000 (19:59 -0300)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Mon, 21 Jan 2019 23:08:52 +0000 (20:08 -0300)
commit0464fdf07f69452dd67dd798c026d82c956bda33
tree9fa1833cdb8f067cdb6f5b650bd5d54225b7febb
parent175544093524bef9c28c59c8d49c77b1fcf4fb92
Create action triggers when partitions are detached

Detaching a partition from a partitioned table that's constrained by
foreign keys requires additional action triggers on the referenced side;
otherwise, DELETE/UPDATE actions there fail to notice rows in the table
that was partition, and so are incorrectly allowed through.  With this
commit, those triggers are now created.  Conversely, when a table that
has a foreign key is attached as a partition to a table that also has
the same foreign key, those action triggers are no longer needed, so we
remove them.

Add a minimal test case verifying (part of) this.

Authors: Amit Langote, Álvaro Herrera
Discussion: https://postgr.es/m/f2b8ead5-4131-d5a8-8016-2ea0a31250af@lab.ntt.co.jp
src/backend/commands/tablecmds.c
src/test/regress/expected/foreign_key.out
src/test/regress/sql/foreign_key.sql