pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gavin Hamill <gdh@laterooms.com>
To: pgsql-performance@postgresql.org
Subject: Re: Slow query - possible bug?
Date: Tue, 18 Apr 2006 21:26:28 +0100
Message-ID: <20060418212628.9aabc45a.gdh@laterooms.com> (raw)
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>

On Tue, 18 Apr 2006 15:51:44 -0400
Tom Lane <tgl@sss.pgh.pa.us> 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.



view thread (10+ messages)

Message-ID: <20060418212628.9aabc45a.gdh@laterooms.com>
Permalink:  ../20060418212628.9aabc45a.gdh@laterooms.com/
Also on:    postgresql.org/message-id/20060418212628.9aabc45a.gdh@laterooms.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: gdh@laterooms.com
  Subject: Re: Slow query - possible bug?
  In-Reply-To: <20060418212628.9aabc45a.gdh@laterooms.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox