X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 9946E9DCD1B for ; Fri, 24 Feb 2006 03:01:31 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 63967-03 for ; Fri, 24 Feb 2006 03:01:30 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from houston.familyhealth.com.au (houston.au.fhnetwork.com [203.22.197.21]) by postgresql.org (Postfix) with ESMTP id AD37C9DCC07 for ; Fri, 24 Feb 2006 03:01:25 -0400 (AST) Received: from houston.familyhealth.com.au (localhost [127.0.0.1]) by houston.familyhealth.com.au (Postfix) with ESMTP id 78DBD2507D; Fri, 24 Feb 2006 15:01:19 +0800 (WST) Received: from [127.0.0.1] (work-40.internal [192.168.0.40]) by houston.familyhealth.com.au (Postfix) with ESMTP id 3B3332507C; Fri, 24 Feb 2006 15:01:18 +0800 (WST) Message-ID: <43FEB07A.7080209@familyhealth.com.au> Date: Fri, 24 Feb 2006 15:06:34 +0800 From: Christopher Kings-Lynne User-Agent: Thunderbird 1.5 (Windows/20051201) MIME-Version: 1.0 To: Brendan Duddridge Cc: PostgreSQL Performance , Tony Copping Subject: Re: Really really slow query. What's a better way? References: <1831440F-F848-471D-ACE9-F84CE9F4E359@clickspace.com> In-Reply-To: <1831440F-F848-471D-ACE9-F84CE9F4E359@clickspace.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-familyhealth-MailScanner-Information: Please contact the ISP for more information X-familyhealth-MailScanner: Found to be clean X-familyhealth-MailScanner-From: chriskl@familyhealth.com.au X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.095 required=5 tests=[AWL=0.095] X-Spam-Score: 0.095 X-Spam-Level: X-Archive-Number: 200602/380 X-Sequence-Number: 17366 how about something like: DELETE FROM cds.cds_mspecxx WHERE NOT EXISTS (SELECT 1 FROM cds_stage.cds_Catalog stage where stage.countryCode = 'us' and stage.ProdId=cds.cds_mspecxx.ProdId) and countryCode = 'us'; Run explain on it first to see how it will be planned. Both tables should have an index over (countryCode, ProdId) I think. Chris Brendan Duddridge wrote: > Hi, > > We're executing a query that has the following plan and we're wondering > given the size of the data set, what's a better way to write the query? > It's been running since 2pm 2 days ago. > > explain DELETE FROM cds.cds_mspecxx WHERE ProdID not in (SELECT > stage.ProdID FROM cds_stage.cds_Catalog stage where stage.countryCode = > 'us') and countryCode = 'us'; > QUERY PLAN > --------------------------------------------------------------------------------------------------- > Index Scan using pk_mspecxx on cds_mspecxx > (cost=53360.87..208989078645.48 rows=7377879 width=6) > Index Cond: ((countrycode)::text = 'us'::text) > Filter: (NOT (subplan)) > SubPlan > -> Materialize (cost=53360.87..77607.54 rows=1629167 width=12) > -> Seq Scan on cds_catalog stage (cost=0.00..43776.70 rows=1629167 width=12) > Filter: ((countrycode)::text = 'us'::text) > (7 rows) > > Thanks, > * > *____________________________________________________________________ > *Brendan Duddridge* | CTO | 403-277-5591 x24 | brendan@clickspace.com > > * > *ClickSpace Interactive Inc. > Suite L100, 239 - 10th Ave. SE > Calgary, AB T2G 0V9 > > http://www.clickspace.com >