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 202D653918 for ; Tue, 29 Mar 2005 17:03:12 +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 97505-06 for ; Tue, 29 Mar 2005 16:03:08 +0000 (GMT) Received: from cmailg2.svr.pol.co.uk (cmailg2.svr.pol.co.uk [195.92.195.172]) by svr1.postgresql.org (Postfix) with ESMTP id 6017C538AD for ; Tue, 29 Mar 2005 17:03:05 +0100 (BST) Received: from modem-2006.porcupine.dialup.pol.co.uk ([217.134.199.214] helo=192.168.0.102) by cmailg2.svr.pol.co.uk with esmtp (Exim 4.14) id 1DGJB7-0005QO-Jj; Tue, 29 Mar 2005 17:02:53 +0100 Subject: Re: Delete query takes exorbitant amount of time From: Simon Riggs To: Tom Lane Cc: Stephan Szabo , Karim A Nassar , Christopher Kings-Lynne , pgsql-performance@postgresql.org In-Reply-To: <22527.1112110310@sss.pgh.pa.us> 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> Content-Type: text/plain Organization: 2nd Quadrant Date: Tue, 29 Mar 2005 17:01:27 +0100 Message-Id: <1112112087.11750.984.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.0.2 (2.0.2-3) Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.062 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200503/636 X-Sequence-Number: 11341 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. Best Regards, Simon Riggs