Avoid bogus scans of partitions when marking FKs enforced
authorÁlvaro Herrera <alvherre@kurilemu.de>
Thu, 5 Jun 2025 16:39:06 +0000 (18:39 +0200)
committerÁlvaro Herrera <alvherre@kurilemu.de>
Thu, 5 Jun 2025 16:39:06 +0000 (18:39 +0200)
commite6f98d8848f1803fda32011998c786a1bf4eb87c
tree571da1f1b9ead3032dda2f4d00b7260116cc398b
parent04acad82b0f912e779795a4661f7d63f5e35b9da
Avoid bogus scans of partitions when marking FKs enforced

Similar to commit cc733ed164c5: when an unenforced foreign key that
references a partitioned table is altered to be enforced, we scan
the constrained table based on each partition on the referenced
partitioned table.  This is bogus and likely to cause the ALTER TABLE to
fail: we must only scan the constrained table as pointing to the
top-level partitioned table.  Oversight in commit eec0040c4bcd.  Fix by
eliding those scans.

Author: Amul Sul <sulamul@gmail.com>
Reported-by: jian he <jian.universality@gmail.com>
Discussion: https://postgr.es/m/CACJufxF1e_gPOLtsDoaE4VCgQPC8KZW_kPAjPR5Rvv4Ew=fb2A@mail.gmail.com
src/backend/commands/tablecmds.c
src/test/regress/expected/foreign_key.out
src/test/regress/sql/foreign_key.sql