pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #18517: Dropping a table referenced by an initially deferred foreign key fails with an error
2+ messages / 2 participants
[nested] [flat]
Commits from this thread:
2024-06-20 e6d0d16adf b0037bbefd 9ce8ee9d3e 4f19666762 1424c7abc4 88f3baa06a Don't throw an error if a queued AFTER trigger no longer exists.
* BUG #18517: Dropping a table referenced by an initially deferred foreign key fails with an error
@ 2024-06-20 11:00 PG Bug reporting form <noreply@postgresql.org>
0 siblings, 1 reply; 2+ messages in thread
From: PG Bug reporting form @ 2024-06-20 11:00 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org; +Cc: exclusion@gmail.com
The following bug has been logged on the website:
Bug reference: 18517
Logged by: Alexander Lakhin
Email address: exclusion@gmail.com
PostgreSQL version: 17beta1
Operating system: Ubuntu 22.04
Description:
The following script:
CREATE TABLE pkt (id int PRIMARY KEY);
CREATE TABLE fkt (id int PRIMARY KEY, fk int REFERENCES pkt INITIALLY
DEFERRED);
INSERT INTO pkt VALUES (1);
BEGIN;
INSERT INTO fkt VALUES (101, 1);
DROP TABLE pkt CASCADE;
COMMIT;
fails on commit with a weird error:
ERROR: relation 16390 has no triggers
BACKTRACE:
afterTriggerInvokeEvents at trigger.c:4700:7
AfterTriggerFireDeferred at trigger.c:5224:6
CommitTransaction at xact.c:2219:8
CommitTransactionCommandInternal at xact.c:3169:18
CommitTransactionCommand at xact.c:3099:9
finish_xact_command at postgres.c:2783:3
exec_simple_query at postgres.c:1299:4
PostgresMain at postgres.c:4684:27
BackendInitialize at backend_startup.c:123:1
postmaster_child_launch at launch_backend.c:269:9
BackendStartup at postmaster.c:3593:8
ServerLoop at postmaster.c:1677:10
PostmasterMain at postmaster.c:1372:11
startup_hacks at main.c:217:1
afterTriggerInvokeEvents() coding is:
/*
* So let's fire it... but first, find the correct relation
if
* this is not the same relation as before.
*/
if (rel == NULL || RelationGetRelid(rel) !=
evtshared->ats_relid)
{
...
if (trigdesc == NULL) /* should not happen */
elog(ERROR, "relation %u has no triggers",
evtshared->ats_relid);
Reproduced on REL_12_STABLE .. master.
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: BUG #18517: Dropping a table referenced by an initially deferred foreign key fails with an error
@ 2024-06-20 16:43 Tom Lane <tgl@sss.pgh.pa.us>
parent: PG Bug reporting form <noreply@postgresql.org>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2024-06-20 16:43 UTC (permalink / raw)
To: exclusion@gmail.com; +Cc: pgsql-bugs@lists.postgresql.org
PG Bug reporting form <noreply@postgresql.org> writes:
> The following script:
> CREATE TABLE pkt (id int PRIMARY KEY);
> CREATE TABLE fkt (id int PRIMARY KEY, fk int REFERENCES pkt INITIALLY
> DEFERRED);
> INSERT INTO pkt VALUES (1);
> BEGIN;
> INSERT INTO fkt VALUES (101, 1);
> DROP TABLE pkt CASCADE;
> COMMIT;
> fails on commit with a weird error:
> ERROR: relation 16390 has no triggers
Oh, interesting. Furthermore, if I add an unrelated trigger to fkt
so that there's still a trigdesc, then I reach
ERROR: XX000: could not find trigger 42452
LOCATION: AfterTriggerExecute, trigger.c:4303
So what this demonstrates is that we should not consider it an
error if afterTriggerInvokeEvents finds an event for a trigger
that no longer exists.
Perhaps an alternative could be to run through the pending events
at DROP time and throw an error if there's an unfired event for the
trigger. That doesn't sound better to me though. I see no very
good reason why we shouldn't allow the above sequence of commands
and treat the constraint as no longer to be enforced.
regards, tom lane
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2024-06-20 16:43 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-06-20 11:00 BUG #18517: Dropping a table referenced by an initially deferred foreign key fails with an error PG Bug reporting form <noreply@postgresql.org>
2024-06-20 16:43 ` Tom Lane <tgl@sss.pgh.pa.us>
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