pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix failure to create FKs correctly in partitions
2+ messages / 1 participants
[nested] [flat]

* pgsql: Fix failure to create FKs correctly in partitions
@ 2020-02-07 21:28  Alvaro Herrera <alvherre@alvh.no-ip.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Alvaro Herrera @ 2020-02-07 21:28 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/55173d2e663fbe32430665ce7bd65a47856dc237

Modified Files
--------------
src/backend/commands/tablecmds.c          | 28 +++++++++++++++++-----------
src/test/regress/expected/foreign_key.out | 24 ++++++++++++++++++++++++
src/test/regress/sql/foreign_key.sql      | 18 ++++++++++++++++++
3 files changed, 59 insertions(+), 11 deletions(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* pgsql: Fix failure to create FKs correctly in partitions
@ 2020-02-07 21:28  Alvaro Herrera <alvherre@alvh.no-ip.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Alvaro Herrera @ 2020-02-07 21:28 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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

Branch
------
REL_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/2c80a656c2b5a2731e5df3c9398a66ffc18cbcf3

Modified Files
--------------
src/backend/commands/tablecmds.c          | 28 +++++++++++++++++-----------
src/test/regress/expected/foreign_key.out | 24 ++++++++++++++++++++++++
src/test/regress/sql/foreign_key.sql      | 18 ++++++++++++++++++
3 files changed, 59 insertions(+), 11 deletions(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2020-02-07 21:28 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-02-07 21:28 pgsql: Fix failure to create FKs correctly in partitions Alvaro Herrera <alvherre@alvh.no-ip.org>
2020-02-07 21:28 pgsql: Fix failure to create FKs correctly in partitions Alvaro Herrera <alvherre@alvh.no-ip.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox