Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id ED01163380D for ; Mon, 22 Mar 2010 16:21:47 -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 29698-10 for ; Mon, 22 Mar 2010 19:21:37 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 558176339CA for ; Mon, 22 Mar 2010 16:21:37 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id o2MJLa5E012445; Mon, 22 Mar 2010 15:21:36 -0400 (EDT) To: Christian Brink cc: pgsql-performance@postgresql.org Subject: Re: PostgreSQL upgraded to 8.2 but forcing index scan on query produces faster In-reply-to: <4BA7C057.9090909@r-stream.com> References: <4BA7C057.9090909@r-stream.com> Comments: In-reply-to Christian Brink message dated "Mon, 22 Mar 2010 15:09:11 -0400" Date: Mon, 22 Mar 2010 15:21:35 -0400 Message-ID: <12444.1269285695@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 201003/281 X-Sequence-Number: 38106 Christian Brink writes: > -> Nested Loop (cost=0.01..2416.59 rows=22477 width=4) > (actual time=0.595..2.150 rows=225 loops=1) > -> Index Scan using sysstrings_pkey on sysstrings > (cost=0.00..8.27 rows=1 width=182) (actual time=0.110..0.112 rows=1 loops=1) > Index Cond: (id = 'net/Console/Employee/Day End > Time'::text) > -> Index Scan using sales_tranzdate_index on sales s > (cost=0.01..1846.40 rows=22477 width=12) (actual time=0.454..1.687 > rows=225 loops=1) > Index Cond: ((s.tranzdate >= ('2010-02-15'::date + > (sysstrings.data)::time without time zone)) AND (s.tranzdate < > ('2010-02-16'::date + (sysstrings.data)::time without time zone))) > Filter: ((NOT void) AND (NOT suspended)) 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. regards, tom lane