X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (mx2.hub.org [200.46.204.254]) by postgresql.org (Postfix) with ESMTP id 1AAC911F60E9 for ; Tue, 18 Apr 2006 17:26:37 -0300 (ADT) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Score: -2.365 X-Spam-Level: X-Spam-Status: No, score=-2.365 required=5 tests=[AWL=0.100, BAYES_00=-2.599, FORGED_RCVD_HELO=0.135, SPF_PASS=-0.001] Received: from postgresql.org ([200.46.204.71]) by localhost (mx2.hub.org [200.46.204.254]) (amavisd-new, port 10024) with ESMTP id 3qDB2dlNpD92 for ; Tue, 18 Apr 2006 17:26:30 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from fon.nation-net.com (fon.nation-net.com [194.24.251.1]) by postgresql.org (Postfix) with ESMTP id 5ACC811F6B77 for ; Tue, 18 Apr 2006 17:26:28 -0300 (ADT) Received: from fon.nation-net.com (localhost [127.0.0.1]) by fon.nation-net.com (Postfix) with ESMTP id E1B68136EA1 for ; Tue, 18 Apr 2006 21:26:26 +0100 (BST) Received: from eddie.acentral.co.uk (80-192-144-33.cable.ubr04.pres.blueyonder.co.uk [80.192.144.33]) by fon.nation-net.com (Postfix) with ESMTP id B5B72136E8B for ; Tue, 18 Apr 2006 21:26:26 +0100 (BST) Received: from eddie.acentral.co.uk (eddie.acentral.co.uk [127.0.0.1]) by eddie.acentral.co.uk (Postfix) with ESMTP id EF28F75A9A for ; Tue, 18 Apr 2006 21:26:28 +0100 (BST) Received: from localhost.localdomain (unknown [10.0.0.29]) by eddie.acentral.co.uk (Postfix) with SMTP id BD57D75A85 for ; Tue, 18 Apr 2006 21:26:28 +0100 (BST) Date: Tue, 18 Apr 2006 21:26:28 +0100 From: Gavin Hamill To: pgsql-performance@postgresql.org Subject: Re: Slow query - possible bug? Message-Id: <20060418212628.9aabc45a.gdh@laterooms.com> In-Reply-To: <18448.1145389904@sss.pgh.pa.us> References: <443E3DF5.4020207@laterooms.com> <3c1395330604130546g6b091f75x511955817fe65dcd@mail.gmail.com> <443E4C9D.3090301@laterooms.com> <20329.1144942010@sss.pgh.pa.us> <44449E4C.7040804@laterooms.com> <14985.1145381508@sss.pgh.pa.us> <20060418200839.1f948672.gdh@laterooms.com> <18448.1145389904@sss.pgh.pa.us> X-Mailer: Sylpheed version 2.2.4 (GTK+ 2.8.17; i486-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: ClamAV using ClamSMTP X-AV-Checked: ClamAV using ClamSMTP X-Archive-Number: 200604/396 X-Sequence-Number: 18480 On Tue, 18 Apr 2006 15:51:44 -0400 Tom Lane wrote: > Fair enough, no reason to replace one workaround with another. But > would you try it on your test case, just to verify the diagnosis? Yup I can confirm it from testing earlier today - as soon as the two dates are non-equal, an index scan is correctly selected and returns results in just a few milliseconds: laterooms=# explain analyse select allocation0_."ID" as y1_, allocation0_."RoomID" as y2_, allocation0_."StatusID" as y4_, allocation0_."Price" as y3_, allocation0_."Number" as y5_, allocation0_."Date" as y6_ from "Allocation" allocation0_ where (allocation0_."Date" between '2006-04-25 00:00:00.000000' and '2006-04-26 00:00:00.000000')and(allocation0_."RoomID" in(211800)); QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------- Index Scan using ix_dateroom on "Allocation" allocation0_ (cost=0.00..14.02 rows=4 width=34) (actual time=16.799..21.804 rows=2 loops=1) Index Cond: (("RoomID" = 211800) AND ("Date" >= '2006-04-25'::date) AND ("Date" <= '2006-04-26'::date)) Total runtime: 21.910 ms which I ran first, versus the identical-date equivalent which turned in a whopping... Index Scan using ix_date on "Allocation" allocation0_ (cost=0.00..4.77 rows=1 width=34) (actual time=6874.272..69541.064 rows=1 loops=1) Index Cond: (("Date" >= '2006-04-25'::date) AND ("Date" <= '2006-04-25'::date)) Filter: ("RoomID" = 211800) Total runtime: 69541.113 ms (4 rows) Cheers, Gavin.