Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 2790BB5DBD8 for ; Tue, 19 Jul 2011 18:45:30 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 97535-03 for ; Tue, 19 Jul 2011 21:45:22 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from gw.wicourts.gov (gwmta.wicourts.gov [165.219.244.99]) by mail.postgresql.org (Postfix) with ESMTP id 27087B5DBCC for ; Tue, 19 Jul 2011 18:45:22 -0300 (ADT) Received: from Courts-MTA by gw.wicourts.gov with Novell_GroupWise; Tue, 19 Jul 2011 16:45:21 -0500 Message-Id: <4E25B49C020000250003F51D@gw.wicourts.gov> X-Mailer: Novell GroupWise Internet Agent 8.0.1 Date: Tue, 19 Jul 2011 16:45:16 -0500 From: "Kevin Grittner" To: "Tom Lane" Cc: Subject: Re: BUG #6123: DELETE fails if before trigger causes another trigger to UPDATE References: <201107191831.p6JIVdxu055846@wwwmaster.postgresql.org><201107191831.p6JIVdxu055846@wwwmaster.postgresql.org> <5769.1311111047@sss.pgh.pa.us> In-Reply-To: <5769.1311111047@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-3.035 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RP_MATCHES_RCVD=-1.135 X-Spam-Level: X-Archive-Number: 201107/141 X-Sequence-Number: 30753 Tom Lane wrote: > "Kevin Grittner" writes: >> [ circular trigger relationships ] > >> I expect the DELETE from a to delete related b record(s) and then >> succeed. Instead the UPDATE in b_del_trig causes delete of a to >> silently fail. > > The update causes the already-selected target row version of the > DELETE to be obsoleted, so heap_delete finds it has nothing to do. > I'm disinclined to mess with that logic. It's pretty astonishing behavior for application programmers. It's not unusual for triggers on detail from one table to maintain a status, count, or sum in a higher level table. When a DELETE from the higher level table causes deletes at the lower level, the lower level trigger really doesn't have any way to know that. I think this should be considered a bug. At the point where heap_delete finds that the tuple has expired, I think it should follow the ctid chain as long as xmax is from the same top-level transaction, and then decide if it has something to do. Normally, that would be zero iterations, so I doubt the performance impact is huge. I'm willing to mess with that logic if there's a chance that it will be accepted. I may *need* to even if it won't, to allow our migration to native PostgreSQL triggers to succeed -- we've been trying to work around it for the last few days, but the places where it's popping up are becoming increasingly hard to accommodate that way. -Kevin