Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 5349D9FB2AB for ; Sat, 14 Oct 2006 21:20:39 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 61331-07 for ; Sat, 14 Oct 2006 21:20:29 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 3609E9FB448 for ; Sat, 14 Oct 2006 21:20:29 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id k9F0KALu013668; Sat, 14 Oct 2006 20:20:10 -0400 (EDT) To: Michael Fuhr cc: PostgreSQL SQL List , Joost Kraaijeveld Subject: Re: Foreign key reference counting strategy? In-reply-to: <20061015001126.GA20713@winnie.fuhr.org> References: <1160828741.28838.9.camel@panoramix> <4530EB84.4050904@logix-tt.com> <20061014234844.GA20342@winnie.fuhr.org> <13525.1160870286@sss.pgh.pa.us> <20061015001126.GA20713@winnie.fuhr.org> Comments: In-reply-to Michael Fuhr message dated "Sat, 14 Oct 2006 18:11:26 -0600" Date: Sat, 14 Oct 2006 20:20:10 -0400 Message-ID: <13667.1160871610@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.089 tagged_above=0 required=5 tests=AWL, SPF_HELO_PASS, SPF_PASS X-Spam-Level: X-Archive-Number: 200610/137 X-Sequence-Number: 26526 Michael Fuhr writes: > On Sat, Oct 14, 2006 at 07:58:06PM -0400, Tom Lane wrote: >> No, I don't think so, because the DELETE will already be holding >> exclusive lock on the doomed PK row, which any would-be inserters of >> matching FK rows will be blocked on. AFAICS the DELETE should go >> through and then the inserters will fail. > Unless the inserters got there first. I just tested both ways; if > the insert acquires the lock first then the delete fails, but if the > delete acquires the lock first then the insert fails. Well, if the inserters get a lock on the PK row before the DELETE does, then of course. I was just disputing the assertion that doing IF EXISTS in an after trigger would add a new way for the DELETE to fail. At that point, any uncommitted inserts must be blocked waiting for the delete. regards, tom lane