X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 3BB0C533B7 for ; Tue, 29 Mar 2005 17:33:27 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 08117-03 for ; Tue, 29 Mar 2005 16:33:25 +0000 (GMT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by svr1.postgresql.org (Postfix) with ESMTP id AE44A52A86 for ; Tue, 29 Mar 2005 17:33:21 +0100 (BST) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 923E4354B1; Tue, 29 Mar 2005 08:33:20 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 8299D3547F; Tue, 29 Mar 2005 08:33:20 -0800 (PST) Date: Tue, 29 Mar 2005 08:33:20 -0800 (PST) From: Stephan Szabo To: Simon Riggs Cc: Tom Lane , Karim A Nassar , Christopher Kings-Lynne , pgsql-performance@postgresql.org Subject: Re: Delete query takes exorbitant amount of time In-Reply-To: <1112112087.11750.984.camel@localhost.localdomain> Message-ID: <20050329083027.I58020@megazone.bigpanda.com> References: <1112095776.11750.958.camel@localhost.localdomain> <20050329054714.V50612@megazone.bigpanda.com> <20050329061837.A51620@megazone.bigpanda.com> <21616.1112108201@sss.pgh.pa.us> <1112109880.11750.977.camel@localhost.localdomain> <22527.1112110310@sss.pgh.pa.us> <1112112087.11750.984.camel@localhost.localdomain> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.004 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200503/637 X-Sequence-Number: 11342 On Tue, 29 Mar 2005, Simon Riggs wrote: > On Tue, 2005-03-29 at 10:31 -0500, Tom Lane wrote: > > Simon Riggs writes: > > > If action is NO ACTION or RESTRICT then > > > we need to SELECT at most 1 row that matches the criteria > > > which means we can use LIMIT 1 > > > > > If action is CASCADE, SET NULL, SET DEFAULT then > > > we need to UPDATE or DELETE all rows that match the criteria > > > which means we musnt use LIMIT and need to use FOR UPDATE > > > > Huh? UPDATE/DELETE don't use FOR UPDATE. I think you have failed > > to break down the cases sufficiently. In particular it matters which > > side of the RI constraint you are working from ... > > OK... too quick, sorry. I'll hand over to Stephan for a better and more > exhaustive explanation/analysis... but AFAICS we *can* always know the > correct formulation of the query prepare time, whether or not we do > currently. We currently use FOR UPDATE on the NO ACTION check, because otherwise we might get back a row that's already marked for deletion by a concurrent transaction. I think that's intended to wait and succeed, not fail.