Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 296729FBCA2 for ; Wed, 30 May 2007 00:22:55 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 48282-03 for ; Wed, 30 May 2007 00:22:46 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 892B79FBC8B for ; Wed, 30 May 2007 00:22:46 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.1/8.14.1) with ESMTP id l4U3IS8Q026150; Tue, 29 May 2007 23:18:28 -0400 (EDT) To: Klint Gore cc: "Tyrrill, Ed" , pgsql-performance@postgresql.org Subject: Re: Very slow left outer join In-reply-to: <465CD94D319.E8C2KG@129.180.47.120> References: <465CD94D319.E8C2KG@129.180.47.120> Comments: In-reply-to Klint Gore message dated "Wed, 30 May 2007 11:54:21 +1000" Date: Tue, 29 May 2007 23:18:28 -0400 Message-ID: <26149.1180495108@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/597 X-Sequence-Number: 24987 Klint Gore writes: > On Tue, 29 May 2007 17:16:57 -0700, "Tyrrill, Ed" wrote: >> mdsdb=# explain analyze select backupobjects.record_id from >> backupobjects left outer join backup_location using(record_id) where >> backup_id = 1071; > Why are you using left join? > The where condition is going to force the row to exist. Which indeed the planner figured out (note the lack of any mention of left join in the EXPLAIN result). Michael put his finger on the problem though: there's something way off about the rowcount estimate here: > -> Bitmap Heap Scan on backup_location (cost=3831.20..360207.21 > rows=436915 width=8) (actual time=94.375..97.688 rows=2789 loops=1) > Recheck Cond: (backup_id = 1071) > -> Bitmap Index Scan on backup_location_bid > (cost=0.00..3831.20 rows=436915 width=0) (actual time=84.239..84.239 > rows=2789 loops=1) > Index Cond: (backup_id = 1071) With such a simple index condition the planner really ought to be able to come close to the right rowcount estimate. Check for vacuuming problems, check for lack of ANALYZE, consider whether you need to bump up the statistics target ... regards, tom lane