mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-10-01 01:31:14 +02:00
Fix GetForeignKey*Triggers for self-referential FKs
Because of inadequate filtering, the check triggers were confusing the
search for action triggers in GetForeignKeyActionTriggers and vice-versa
in GetForeignKeyCheckTriggers; this confusion results in seemingly
random assertion failures, and can have real impact in non-asserting
builds depending on catalog order. Change these functions so that they
correctly ignore triggers that are not relevant to each side.
To reduce the odds of further problems, do not break out of the
searching loop in assertion builds. This break is likely to hide bugs;
without it, we would have detected this bug immediately.
This problem was introduced by f4566345cf
, so backpatch to 15 where
that commit first appeared.
Author: Amit Langote <amitlangote09@gmail.com>
Discussion: https://postgr.es/m/20220908172029.sejft2ppckbo6oh5@awork3.anarazel.de
Discussion: https://postgr.es/m/4104619.1662663056@sss.pgh.pa.us
This commit is contained in:
parent
0a7c9ee500
commit
68b0da6779
@ -10615,6 +10615,9 @@ GetForeignKeyActionTriggers(Relation trigrel,
|
|||||||
continue;
|
continue;
|
||||||
if (trgform->tgrelid != confrelid)
|
if (trgform->tgrelid != confrelid)
|
||||||
continue;
|
continue;
|
||||||
|
/* Only ever look at "action" triggers on the PK side. */
|
||||||
|
if (RI_FKey_trigger_type(trgform->tgfoid) != RI_TRIGGER_PK)
|
||||||
|
continue;
|
||||||
if (TRIGGER_FOR_DELETE(trgform->tgtype))
|
if (TRIGGER_FOR_DELETE(trgform->tgtype))
|
||||||
{
|
{
|
||||||
Assert(*deleteTriggerOid == InvalidOid);
|
Assert(*deleteTriggerOid == InvalidOid);
|
||||||
@ -10625,8 +10628,11 @@ GetForeignKeyActionTriggers(Relation trigrel,
|
|||||||
Assert(*updateTriggerOid == InvalidOid);
|
Assert(*updateTriggerOid == InvalidOid);
|
||||||
*updateTriggerOid = trgform->oid;
|
*updateTriggerOid = trgform->oid;
|
||||||
}
|
}
|
||||||
|
#ifndef USE_ASSERT_CHECKING
|
||||||
|
/* In an assert-enabled build, continue looking to find duplicates */
|
||||||
if (OidIsValid(*deleteTriggerOid) && OidIsValid(*updateTriggerOid))
|
if (OidIsValid(*deleteTriggerOid) && OidIsValid(*updateTriggerOid))
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!OidIsValid(*deleteTriggerOid))
|
if (!OidIsValid(*deleteTriggerOid))
|
||||||
@ -10670,6 +10676,9 @@ GetForeignKeyCheckTriggers(Relation trigrel,
|
|||||||
continue;
|
continue;
|
||||||
if (trgform->tgrelid != conrelid)
|
if (trgform->tgrelid != conrelid)
|
||||||
continue;
|
continue;
|
||||||
|
/* Only ever look at "check" triggers on the FK side. */
|
||||||
|
if (RI_FKey_trigger_type(trgform->tgfoid) != RI_TRIGGER_FK)
|
||||||
|
continue;
|
||||||
if (TRIGGER_FOR_INSERT(trgform->tgtype))
|
if (TRIGGER_FOR_INSERT(trgform->tgtype))
|
||||||
{
|
{
|
||||||
Assert(*insertTriggerOid == InvalidOid);
|
Assert(*insertTriggerOid == InvalidOid);
|
||||||
@ -10680,8 +10689,11 @@ GetForeignKeyCheckTriggers(Relation trigrel,
|
|||||||
Assert(*updateTriggerOid == InvalidOid);
|
Assert(*updateTriggerOid == InvalidOid);
|
||||||
*updateTriggerOid = trgform->oid;
|
*updateTriggerOid = trgform->oid;
|
||||||
}
|
}
|
||||||
|
#ifndef USE_ASSERT_CHECKING
|
||||||
|
/* In an assert-enabled build, continue looking to find duplicates. */
|
||||||
if (OidIsValid(*insertTriggerOid) && OidIsValid(*updateTriggerOid))
|
if (OidIsValid(*insertTriggerOid) && OidIsValid(*updateTriggerOid))
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!OidIsValid(*insertTriggerOid))
|
if (!OidIsValid(*insertTriggerOid))
|
||||||
|
Loading…
Reference in New Issue
Block a user