pgsql: Fix GetForeignKey*Triggers for self-referential FKs

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix GetForeignKey*Triggers for self-referential FKs
Date: 2022-09-09 10:23:38
Message-ID: E1oWbAf-0028Mw-IY@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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 f4566345cf40, so backpatch to 15 where
that commit first appeared.

Author: Amit Langote <amitlangote09(at)gmail(dot)com>
Discussion: https://postgr.es/m/20220908172029.sejft2ppckbo6oh5@awork3.anarazel.de
Discussion: https://postgr.es/m/4104619.1662663056@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/8c848cd4b8e9e0fee33eaad33cb44376b9e5b480

Modified Files
--------------
src/backend/commands/tablecmds.c | 12 ++++++++++++
1 file changed, 12 insertions(+)

Browse pgsql-committers by date

  From Date Subject
Next Message Alvaro Herrera 2022-09-09 11:52:43 pgsql: Doc fixes for MERGE statement
Previous Message John Naylor 2022-09-09 07:06:34 Re: pgsql: Choose FK name correctly during partition attachment