Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 30487632EA0 for ; Wed, 24 Mar 2010 13:07:17 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 89384-09 for ; Wed, 24 Mar 2010 16:07:06 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.r-stream.com (unknown [69.64.160.121]) by mail.postgresql.org (Postfix) with ESMTP id 6AEEE63224C for ; Wed, 24 Mar 2010 13:07:06 -0300 (ADT) Received: by mail.r-stream.com (Postfix, from userid 109) id AE3FF7FB4; Wed, 24 Mar 2010 11:09:56 -0500 (CDT) Received: from [192.168.1.127] (rrcs-67-78-3-246.se.biz.rr.com [67.78.3.246]) by mail.r-stream.com (Postfix) with ESMTP id 2E4AE7FA4; Wed, 24 Mar 2010 11:09:56 -0500 (CDT) Message-ID: <4BAA388B.7090301@r-stream.com> Date: Wed, 24 Mar 2010 12:06:35 -0400 From: Christian Brink User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9pre) Gecko/20100217 Lightning/1.0b1 Shredder/3.0.3pre MIME-Version: 1.0 To: Tom Lane CC: pgsql-performance@postgresql.org, peger@automotive.com Subject: Re: PostgreSQL upgraded to 8.2 but forcing index scan on query produces faster References: <4BA7C057.9090909@r-stream.com> <12444.1269285695@sss.pgh.pa.us> In-Reply-To: <12444.1269285695@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.499 tagged_above=-10 required=5 tests=BAYES_00=-2.599, RDNS_NONE=0.1 X-Spam-Level: X-Archive-Number: 201003/309 X-Sequence-Number: 38134 On 03/22/2010 03:21 PM, Tom Lane wrote: > The fundamental reason why you're getting a bad plan choice is the > factor-of-100 estimation error here. I'm not sure you can do a whole > lot about that without rethinking the query --- in particular I would > suggest trying to get rid of the non-constant range bounds. You're > apparently already plugging in an external variable for the date, > so maybe you could handle the time of day similarly instead of joining > to sysstrings for it. > > Tom & Peter, I thought you might like to know the outcome of this. I was able to get the 8.0 and the 8.2 planner to correctly run the query. There were 2 issues. As Tom pointed out the the 'systrings' lookup seems to be the main culprit. Which makes sense. How can the planner know how to run the query when it doesn't know approximately what it will bracket the until the query has started? The other part of the solution is bit concerning. I had to do a 'dump and load' (and vacuum analyze) to get the planner to work correctly even after I rewrote the query. FYI I had run 'VACUUM ANALYZE' (and sometimes 'REINDEX TABLE x') between each test. -- Christian Brink