Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id B350A635B5F for ; Tue, 24 Mar 2009 23:30:32 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 94963-02 for ; Tue, 24 Mar 2009 23:30:17 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from outmail128173.authsmtp.co.uk (outmail128173.authsmtp.co.uk [62.13.128.173]) by mail.postgresql.org (Postfix) with ESMTP id 62253635561 for ; Tue, 24 Mar 2009 23:30:24 -0300 (ADT) Received: from mail-c187.authsmtp.com (mail-c187.authsmtp.com [62.13.128.33]) by punt8.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id n2P2ULFe073436; Wed, 25 Mar 2009 02:30:21 GMT Received: from Sidney-Stratton.local (adsl-63-195-55-98.dsl.snfc21.pacbell.net [63.195.55.98]) (authenticated bits=0) by mail.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id n2P2UIuh044392; Wed, 25 Mar 2009 02:30:19 GMT Message-ID: <49C99732.8080703@agliodbs.com> Date: Tue, 24 Mar 2009 19:30:10 -0700 From: Josh Berkus Organization: Aglio Database Solutions User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1b3pre) Gecko/20090223 Thunderbird/3.0b2 MIME-Version: 1.0 To: Bryan Murphy CC: pgsql-performance@postgresql.org Subject: Re: Help Me Understand Why I'm Getting a Bad Query Plan References: <7fd310d10903231203r1bd37b8cn8baeadae83253f44@mail.gmail.com> <7fd310d10903241521t645462bdpb3b8aee40b4f3ae4@mail.gmail.com> In-Reply-To: <7fd310d10903241521t645462bdpb3b8aee40b4f3ae4@mail.gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Server-Quench: e2fae43b-18e4-11de-8156-001185d377ca X-AuthRoute: OCdyZgscClZXSx8a IioLCC5HRQ8+YBZL BAkGMA9GIUINWEQL c1AAcx12OUdbHwkB CnYLWV5XUFdzWS1z aBRQZABDZ09QVg11 Uk1LR01SWltqYR5k f1tGUh12dAxENn93 bEcsC3INDRF+dhRg Q0YBEXAHZDM1dWge VUZFdwNVcQtPKhxC bQMuGhFYa3VsBg8C MSgJGgV5HThbMGxw T0kwK14fW10XFzgw Dy8CDH0OUkhNaCgv Mx0gJRYVVGwYPg0L LFY7SBogNxYUYiwg X-Authentic-SMTP: 61633136333939.squirrel.dmpriest.net.uk:1378/Kp X-Report-SPAM: If SPAM / abuse - report it at: http://www.authsmtp.com/abuse X-Virus-Status: No virus detected - but ensure you scan with your own anti-virus system. X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200903/358 X-Sequence-Number: 33280 Brian, > I hate to nag, but could anybody help me with this? We have a few > related queries that are causing noticeable service delays in our > production system. I've tried a number of different things, but I'm > running out of ideas and don't know what to do next. For some reason, your first post didn't make it to the list, which is why nobody responded. >> I've got a query on our production system that isn't choosing a good >> plan. I can't see why it's choosing to do a sequential scan on the >> ItemExperienceLog table. That table is about 800mb and has about 2.5 >> million records. This example query only returns 4 records. I've >> tried upping the statics for ItemExperienceLog.VistorId and >> ItemExperienceLog.ItemId to 1000 (from out default of 100) with no >> success. Yes, that is kind of inexplicable. For some reason, it's assigning a very high cost to the nestloops, which is why it wants to avoid them with a seq scan. Can you try lowering cpu_index_cost to 0.001 and see how that affects the plan? --Josh