1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-03 20:02:46 +03:00

Avoid bogus scans of partitions when marking FKs enforced

Similar to commit cc733ed164: 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 eec0040c4b.  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
This commit is contained in:
Álvaro Herrera
2025-06-05 18:39:06 +02:00
parent 04acad82b0
commit e6f98d8848
3 changed files with 37 additions and 22 deletions

View File

@ -12466,9 +12466,12 @@ ATExecAlterConstrEnforceability(List **wqueue, ATAlterConstraint *cmdcon,
/*
* Tell Phase 3 to check that the constraint is satisfied by existing
* rows.
* rows. Only applies to leaf partitions, and (for constraints that
* reference a partitioned table) only if this is not one of the
* pg_constraint rows that exist solely to support action triggers.
*/
if (rel->rd_rel->relkind == RELKIND_RELATION)
if (rel->rd_rel->relkind == RELKIND_RELATION &&
currcon->confrelid == pkrelid)
{
AlteredTableInfo *tab;
NewConstraint *newcon;