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 EB5155352A for ; Tue, 29 Mar 2005 18:19:36 +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 23160-04 for ; Tue, 29 Mar 2005 17:19:27 +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 1AB33534A3 for ; Tue, 29 Mar 2005 18:19:25 +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 1DGKMy-0003l7-8U; Tue, 29 Mar 2005 18:19:12 +0100 Subject: Re: Delete query takes exorbitant amount of time From: Simon Riggs To: Tom Lane Cc: Karim A Nassar , Stephan Szabo , Christopher Kings-Lynne , pgsql-performance@postgresql.org In-Reply-To: <21461.1112107257@sss.pgh.pa.us> References: <1112095776.11750.958.camel@localhost.localdomain> <21461.1112107257@sss.pgh.pa.us> Content-Type: text/plain Organization: 2nd Quadrant Date: Tue, 29 Mar 2005 18:17:45 +0100 Message-Id: <1112116665.11750.1017.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.061 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200503/639 X-Sequence-Number: 11344 On Tue, 2005-03-29 at 09:40 -0500, Tom Lane wrote: > Simon Riggs writes: > > ...but, I see no way for OidFunctionCall8 to ever return an answer of > > "always just 1 row, no matter how big the relation"...so tuples_fetched > > is always proportional to the size of the relation. Are unique indexes > > treated just as very-low-selectivity indexes? > > Yeah. It is not the job of amcostestimate to estimate the number of > rows, only the index access cost. (IIRC there is someplace in the > planner that explicitly considers unique indexes as a part of developing > selectivity estimates ... but it's not that part.) Well, I mention this because costsize.c:cost_index *does* calculate the number of rows returned. If unique indexes are handled elsewhere then this would not cause problems for them...but for LIMIT queries..? cost_index gets the selectivity then multiplies that by number of tuples in the relation to calc tuples_fetched, so it can use that in the Mackert & Lohman formula. There's no consideration of the query limits. That implies to me that LIMIT queries are not considered correctly in the M&L formula and thus we are more likely to calculate a too-high cost for using an index in those circumstances....and thus more likely to SeqScan for medium sized relations? Best Regards, Simon Riggs