Received: from localhost (unknown [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 39DA29F94A0 for ; Thu, 4 Oct 2007 09:31:02 -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 78756-10 for ; Thu, 4 Oct 2007 09:30:49 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from lists.commandprompt.com (host-254.commandprompt.net [207.173.203.254]) by postgresql.org (Postfix) with ESMTP id 067439F949D for ; Thu, 4 Oct 2007 09:30:52 -0300 (ADT) Received: from perhan.alvh.no-ip.org (201-220-98-36.bk9-dsl.surnet.cl [201.220.98.36]) (authenticated bits=0) by lists.commandprompt.com (8.13.7/8.13.6) with ESMTP id l94CUeQP013301; Thu, 4 Oct 2007 05:30:42 -0700 Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 7CFEC47C6E; Thu, 4 Oct 2007 08:30:38 -0400 (CLT) Date: Thu, 4 Oct 2007 08:30:38 -0400 From: Alvaro Herrera To: Henrik Cc: Tom Lane , pgsql-performance@postgresql.org Subject: Re: Query taking too long. Problem reading explain output. Message-ID: <20071004123038.GA6176@alvh.no-ip.org> References: <15793.1191420918@sss.pgh.pa.us> <2E2D02AB-123A-474D-A197-91A61DC64570@mac.se> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2E2D02AB-123A-474D-A197-91A61DC64570@mac.se> User-Agent: Mutt/1.5.16 (2007-06-11) X-Virus-Scanned: ClamAV 0.91.1/4466/Wed Oct 3 22:05:43 2007 on projects.commandprompt.com X-Virus-Status: Clean X-Greylist: Sender succeded SMTP AUTH authentication, not delayed by milter-greylist-1.6 (lists.commandprompt.com [192.168.2.159]); Thu, 04 Oct 2007 05:30:43 -0700 (PDT) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200710/28 X-Sequence-Number: 27050 Henrik wrote: > Ahh I had exactly 8 joins. > Following your suggestion I raised the join_collapse_limit from 8 to 10 and > the planners decision sure changed but now I have some crazy nested loops. > Maybe I have some statistics wrong? Yeah. The problematic misestimation is exactly the innermost indexscan, which is wrong by two orders of magnitude: > -> Index Scan using > tbl_file_idx on tbl_file (cost=0.01..8.66 rows=1 width=39) (actual > time=0.057..931.546 rows=2223 loops=1) > Index Cond: > ((lower((file_name)::text) ~>=~ 'index.php'::character varying) AND > (lower((file_name)::text) ~<~ 'index.phq'::character varying)) > Filter: > (lower((file_name)::text) ~~ 'index.php%'::text) This wreaks havoc on the rest of the plan. If this weren't misestimated, it wouldn't be using those nested loops. -- Alvaro Herrera http://www.CommandPrompt.com/ PostgreSQL Replication, Consulting, Custom Development, 24x7 support