]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix failure to create FKs correctly in partitions
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Fri, 7 Feb 2020 21:27:18 +0000 (18:27 -0300)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Fri, 7 Feb 2020 21:27:18 +0000 (18:27 -0300)
commit2c80a656c2b5a2731e5df3c9398a66ffc18cbcf3
tree0445fd298ff830d31fe7134cfab5ab32be938324
parentce054a8cd4f4faf3479050feb5d8fa08545f4c5c
Fix failure to create FKs correctly in partitions

On a multi-level partioned table, when adding a partition not directly
connected to the root table, foreign key constraints referencing the
root were not cloned to the new partition, leading to the FK being
possibly inadvertently violated later on.

This was caused by fuzzy thinking in CloneFkReferenced (commit
f56f8f8da6af): it was skipping constraints marked as having parents on
the theory that cloning those would create duplicates; but that's only
correct for the top level of the partitioning hierarchy.  For levels
below that one, such constraints must still be considered and only
skipped if later on we see that we'd create duplicates.  Apparently, I
(Álvaro) wrote the comments right but the code implemented something
slightly different.

Author: Jehan-Guillaume de Rorthais
Discussion: https://postgr.es/m/20200206004948.238352db@firost
src/backend/commands/tablecmds.c
src/test/regress/expected/foreign_key.out
src/test/regress/sql/foreign_key.sql