Re: surprising trigger/foreign key interaction

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Stefan Kaltenbrunner <stefan(at)kaltenbrunner(dot)cc>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: surprising trigger/foreign key interaction
Date: 2009-08-12 22:26:05
Message-ID: 20090812222605.GP5721@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tom Lane wrote:
> Stefan Kaltenbrunner <stefan(at)kaltenbrunner(dot)cc> writes:
> > the "surprise" here was that the delete is getting silently surpressed
> > even though the original Qual still holds and afaik should result in the
> > row deleted.
>
> The delete from foo acts first (since you put it in a BEFORE trigger).
> After the trigger comes back, the outer delete finds itself trying
> to delete a row that was already updated by a later-starting command in
> the same transaction.

Hmm, I misread the code when talking to Stefan on IM. I followed the
path that heap_update returns HeapTupleUpdated, which proceeds to do
EvalPlanQual and attempt to update the updated version of the row.
However I'm guessing that what actually happens is that heap_update is
returning HeapTupleSelfUpdated instead, which the code states as
/* nothing to do */.

I imagine this is so because of some old fiddling to get semantics just
right for obscure corner cases, but it feels wrong nevertheless.

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Josh Berkus 2009-08-12 22:33:29 Re: Alpha 1 release notes
Previous Message Alvaro Herrera 2009-08-12 22:20:39 Re: COPY speedup