From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andres Freund <andres@anarazel.de>
Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>
Cc: Jehan-Guillaume de Rorthais <jgdr@dalibo.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: [BUG] wrong FK constraint name when colliding name on ATTACH
Date: Thu, 08 Sep 2022 15:54:33 -0400
Message-ID: <4118054.1662666873@sss.pgh.pa.us> (raw)
In-Reply-To: <20220908172029.sejft2ppckbo6oh5@awork3.anarazel.de>
References: <20220908094026.640a0224@karst>
<20220908112515.5pe5obtk4a63aiee@alvherre.pgsql>
<20220908172029.sejft2ppckbo6oh5@awork3.anarazel.de>
Andres Freund <andres@anarazel.de> writes:
> Something here doesn't look to be quite right. Starting with this commit CI
> [1] started to fail on freebsd (stack trace [2]), and in the meson branch I've
> also seen the crash on windows (CI run[3], stack trace [4]).
The crash seems 100% reproducible if I remove the early-exit optimization
from GetForeignKeyActionTriggers:
inline patch 1: src/backend/commands/tablecmds.c (+0/-2 lines) download inline-1.patchdiff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.cindex 53b0f3a9c1..112ca77d97 100644--- a/src/backend/commands/tablecmds.c+++ b/src/backend/commands/tablecmds.c@@ -10591,8 +10591,6 @@ GetForeignKeyActionTriggers(Relation trigrel,
Assert(*updateTriggerOid == InvalidOid);
*updateTriggerOid = trgform->oid;
}
- if (OidIsValid(*deleteTriggerOid) && OidIsValid(*updateTriggerOid))- break;
}
if (!OidIsValid(*deleteTriggerOid))
With that in place, it's probabilistic whether the Asserts notice anything
wrong, and mostly they don't. But there are multiple matching triggers:
regression=# select oid, tgconstraint, tgrelid,tgconstrrelid, tgtype, tgname from pg_trigger where tgconstraint = 104301;
oid | tgconstraint | tgrelid | tgconstrrelid | tgtype | tgname
--------+--------------+---------+---------------+--------+-------------------------------
104302 | 104301 | 104294 | 104294 | 9 | RI_ConstraintTrigger_a_104302
104303 | 104301 | 104294 | 104294 | 17 | RI_ConstraintTrigger_a_104303
104304 | 104301 | 104294 | 104294 | 5 | RI_ConstraintTrigger_c_104304
104305 | 104301 | 104294 | 104294 | 17 | RI_ConstraintTrigger_c_104305
(4 rows)
I suspect that the filter conditions being applied are inadequate
for the case of a self-referential FK, which this evidently is
given that tgrelid and tgconstrrelid are equal.
I'd counsel dropping the early-exit optimization; it doesn't
save much I expect, and it evidently hides bugs. Or maybe
make it conditional on !USE_ASSERT_CHECKING.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: tgl@sss.pgh.pa.us, andres@anarazel.de, alvherre@alvh.no-ip.org, jgdr@dalibo.com
Subject: Re: [BUG] wrong FK constraint name when colliding name on ATTACH
In-Reply-To: <4118054.1662666873@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox