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 commitcc733ed164
: 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 commiteec0040c4b
. 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:
@ -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;
|
||||
|
Reference in New Issue
Block a user