Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 03EC61337BDD for ; Tue, 9 Nov 2010 18:51:04 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 93701-02-5 for ; Tue, 9 Nov 2010 22:50:57 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from marajade.localdomain (vcs5.camavision.com [63.228.164.252]) by mail.postgresql.org (Postfix) with ESMTP id 5104C1337BC1 for ; Tue, 9 Nov 2010 18:47:42 -0400 (AST) Received: from [192.168.10.84] (unknown [192.168.10.84]) (Authenticated sender: andy) by marajade.localdomain (Postfix) with ESMTPA id EC1734A39E; Tue, 9 Nov 2010 16:47:40 -0600 (CST) Message-ID: <4CD9CFA4.7030600@squeakycode.net> Date: Tue, 09 Nov 2010 16:48:04 -0600 From: Andy Colson User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101027 Lightning/1.0b2 Thunderbird/3.1.6 MIME-Version: 1.0 To: bricklen CC: pgsql-performance@postgresql.org Subject: Re: Huge overestimation in rows expected results in bad plan References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201011/120 X-Sequence-Number: 41144 On 11/9/2010 3:26 PM, bricklen wrote: > Hi, > > I have a query that is getting a pretty bad plan due to a massively > incorrect count of expected rows. All tables in the query were vacuum > analyzed right before the query was tested. Disabling nested loops > gives a significantly faster result (4s vs 292s). > Any thoughts on what I can change to make the planner generate a better plan? > > > explain analyze > select c.id, c.transactionid, c.clickgenerated, c.confirmed, > c.rejected, cr.rejectedreason > from conversion c > inner join conversionrejected cr on cr.idconversion = c.id > where date = '2010-11-06' > and idaction = 12906 > and idaffiliate = 198338 > order by transactionid; > > > -> Seq Scan on conversionrejected cr (cost=0.00..191921.82 > rows=11012682 width=31) (actual time=0.003..1515.816 rows=11012682 > loops=72) > Total runtime: 292668.992 ms > > > > Looks like the table stats are ok. But its doing a sequential scan. Are you missing an index? Also: http://explain.depesz.com/ is magic. -Andy