]> granicus.if.org Git - postgresql/commit
Fix ALTER/TYPE on columns referenced by FKs in partitioned tables
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Fri, 14 Sep 2018 16:57:30 +0000 (13:57 -0300)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Fri, 14 Sep 2018 17:22:22 +0000 (14:22 -0300)
commit6009bad9134782babfc45c6bae6cfbca7f4899d0
treead0f985bec3f5aa0c8f4716d4c61bf2b9ad13c71
parent830d7565902f8d1da5f07259982a6a54dc65e40d
Fix ALTER/TYPE on columns referenced by FKs in partitioned tables

When ALTER TABLE ... SET DATA TYPE affects a column referenced by
constraints and indexes, it drop those constraints and indexes and
recreates them afterwards, so that the definitions match the new data
type.  The original code did this by dropping one object at a time
(commit 077db40fa1f3 of May 2004), which worked fine because the
dependencies between the objects were pretty straightforward, and
ordering the objects in a specific way was enough to make this work.
However, when there are foreign key constraints in partitioned tables,
the dependencies are no longer so straightforward, and we were getting
errors when attempted:
  ERROR:  cache lookup failed for constraint 16398

This can be fixed by doing all the drops in one pass instead, using
performMultipleDeletions (introduced by df18c51f2955 of Aug 2006).  With
this change we can also remove the code to carefully order the list of
objects to be deleted.

Reported-by: Rajkumar Raghuwanshi <rajkumar.raghuwanshi@enterprisedb.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAKcux6nWS_m+s=1Udk_U9B+QY7pA-Ac58qR5BdUfOyrwnWHDew@mail.gmail.com
src/backend/commands/tablecmds.c
src/test/regress/expected/foreign_key.out
src/test/regress/sql/foreign_key.sql