Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id EDBAD9FB484 for ; Mon, 21 May 2007 12:10:12 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 99877-06 for ; Mon, 21 May 2007 12:09:56 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from k2smtpout03-02.prod.mesa1.secureserver.net (k2smtpout03-02.prod.mesa1.secureserver.net [64.202.189.172]) by postgresql.org (Postfix) with SMTP id 30B9F9FB43C for ; Mon, 21 May 2007 12:10:01 -0300 (ADT) Received: (qmail 18898 invoked from network); 21 May 2007 15:10:00 -0000 Received: from unknown (HELO mail.servantwebhosting.com) (68.178.159.82) by k2smtpout03-02.prod.mesa1.secureserver.net (64.202.189.172) with ESMTP; 21 May 2007 15:09:59 -0000 Received: (qmail 7457 invoked by uid 2527); 21 May 2007 08:09:59 -0700 Received: from 70.64.210.50 by jonah.prod.phx1.secureserver.net (envelope-from , uid 2525) with qmail-scanner-1.25-st-qms (clamdscan: 0.86.2/989. spamassassin: 3.1.8. perlscan: 1.25-st-qms. Clear:RC:0(70.64.210.50):SA:0(1.4/5.0):. Processed in 2.412661 secs); 21 May 2007 15:09:59 -0000 X-Antivirus-MYDOMAIN-Mail-From: pgsql-performance@nullmx.com via jonah.prod.phx1.secureserver.net X-Antivirus-MYDOMAIN: 1.25-st-qms (Clear:RC:0(70.64.210.50):SA:0(1.4/5.0):. Processed in 2.412661 secs Process 7436) X-Envelope-From: pgsql-performance@nullmx.com Received: from s010600e0296eec95.mj.shawcable.net (HELO shach) (rob@nullmx.com@70.64.210.50) by mail.servantwebhosting.com with SMTP; 21 May 2007 08:09:56 -0700 From: "Chuck D." Reply-To: pgsql-performance@nullmx.com To: pgsql-performance@postgresql.org Subject: Re: Rewriting DISTINCT and losing performance Date: Mon, 21 May 2007 09:09:43 -0600 User-Agent: KMail/1.9.5 References: <200705202228.32129.pgsql-performance@nullmx.com> <465162E6.4030205@agliodbs.com> In-Reply-To: <465162E6.4030205@agliodbs.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200705210909.44335.pgsql-performance@nullmx.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/392 X-Sequence-Number: 24782 On Monday 21 May 2007 03:14, Josh Berkus wrote: > Chuck, > > Can we see the plan? > > --Josh > Sorry Josh, I guess I could have just used EXPLAIN instead of EXPLAIN ANALYZE. # explain SELECT country_id, country_name FROM geo.country WHERE country_id IN (select country_id FROM geo.city) ; QUERY PLAN -------------------------------------------------------------------- Nested Loop IN Join (cost=0.00..1252.60 rows=155 width=15) Join Filter: (country.country_id = city.country_id) -> Seq Scan on country (cost=0.00..6.44 rows=244 width=15) -> Seq Scan on city (cost=0.00..43409.12 rows=2122712 width=2) (4 rows) Versus the same query using the older, larger world_city table: # explain SELECT country_id, country_name FROM geo.country WHERE country_id IN (select country_id FROM geo.world_city) ; QUERY PLAN -------------------------------------------------------------------------------------------------------- Nested Loop IN Join (cost=0.00..23.16 rows=155 width=15) -> Seq Scan on country (cost=0.00..6.44 rows=244 width=15) -> Index Scan using idx_world_city_country_id on world_city (cost=0.00..706.24 rows=12602 width=2) Index Cond: (country.country_id = world_city.country_id) (4 rows)