Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id A77779FB91C for ; Fri, 18 May 2007 19:32:40 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 30367-10 for ; Fri, 18 May 2007 19:32:36 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from cassarossa.samfundet.no (cassarossa.samfundet.no [129.241.93.19]) by postgresql.org (Postfix) with ESMTP id C89CF9FB8E5 for ; Fri, 18 May 2007 19:32:36 -0300 (ADT) Received: from trofast.sesse.net ([129.241.93.32]) by cassarossa.samfundet.no with esmtp (Exim 4.50) id 1HpAzy-0000Dc-9N for pgsql-performance@postgresql.org; Sat, 19 May 2007 00:32:34 +0200 Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian)) id 1HpAzx-0004cr-00 for ; Sat, 19 May 2007 00:32:33 +0200 Date: Sat, 19 May 2007 00:32:33 +0200 From: "Steinar H. Gunderson" To: pgsql-performance@postgresql.org Subject: Re: CPU Intensive query Message-ID: <20070518223233.GB17690@uio.no> Mail-Followup-To: pgsql-performance@postgresql.org References: <20070518164210.GA15372@uio.no> <545855.84387.qm@web57106.mail.re3.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <545855.84387.qm@web57106.mail.re3.yahoo.com> X-Operating-System: Linux 2.6.20.4 on a x86_64 X-Message-Flag: Outlook? --> http://www.mozilla.org/products/thunderbird/ User-Agent: Mutt/1.5.13 (2006-08-11) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/353 X-Sequence-Number: 24743 On Fri, May 18, 2007 at 02:37:27PM -0700, Abu Mushayeed wrote: >>> set enable_nestloop = off; >> What's the rationale for this? > To eliminate nested loop. It does a nested loop betwwen to very large > table(millions of rows). If the planner chooses a nested loop, it is because it believes it is the most efficient solution. I'd turn it back on and try to figure out why the planner was wrong. Note that a nested loop with an index scan on one or both sides can easily be as efficient as anything. Did you ANALYZE your tables recently? If the joins are really between millions of rows and the planner thinks it's a couple thousands, the stats sound rather off... >>> HashAggregate (cost=152555.97..152567.32 rows=267 width=162) >> 152000 disk page fetches is a bit, but it shouldn't take 24 hours. There's >> probably misestimation involved at some point here. Does it really return 267 >> rows, or many more? > It returns finally about 19-20 thousand rows. So the planner is off by a factor of at least a hundred. That's a good first-level explanation for why it's slow, at least... If you can, please provide EXPLAIN ANALYZE output for your query (after running ANALYZE on all your tables, if you haven't already); even though it will take some time, it usually makes this kind of performance debugging much easier. /* Steinar */ -- Homepage: http://www.sesse.net/