Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 51EC9B5DBD9 for ; Tue, 19 Jul 2011 19:10:48 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 53823-04 for ; Tue, 19 Jul 2011 22:10:42 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 21A6BB5DBCC for ; Tue, 19 Jul 2011 19:10:42 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id p6JMAfrg011541; Tue, 19 Jul 2011 18:10:41 -0400 (EDT) To: "Kevin Grittner" cc: pgsql-bugs@postgresql.org Subject: Re: BUG #6123: DELETE fails if before trigger causes another trigger to UPDATE In-reply-to: <4E25B49C020000250003F51D@gw.wicourts.gov> References: <201107191831.p6JIVdxu055846@wwwmaster.postgresql.org><201107191831.p6JIVdxu055846@wwwmaster.postgresql.org> <5769.1311111047@sss.pgh.pa.us> <4E25B49C020000250003F51D@gw.wicourts.gov> Comments: In-reply-to "Kevin Grittner" message dated "Tue, 19 Jul 2011 16:45:16 -0500" Date: Tue, 19 Jul 2011 18:10:41 -0400 Message-ID: <11540.1311113441@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-3.093 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RP_MATCHES_RCVD=-1.193 X-Spam-Level: X-Archive-Number: 201107/142 X-Sequence-Number: 30754 "Kevin Grittner" writes: > Tom Lane wrote: >> 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. I think you have no idea how large a can of worms you're opening. To point out just one problem, if heap_delete restarts itself and tries to delete some other row version than it started with, should the ON DELETE triggers be fired again? If not, why not? If they are, what prevents an infinite loop? IMO, application code that causes this to happen is impossibly fragile and needs to be rewritten to not do it. regards, tom lane