pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Marc G. Fournier <scrappy@postgresql.org>
To: pgsql-sql@postgresql.org
Subject: timestamp query doesn't use an index ...
Date: Sat, 20 May 2006 22:42:00 -0300 (ADT)
Message-ID: <20060520223704.T1114@ganymede.hub.org> (raw)


I'm trying to figure out some way to speed up the following query:

   select ps2.page_id, ps2.template_component_id, max(ps2.start_time)
     from page_schedule ps2
    where ps2.start_time at time zone 'MST7MDT' <= '2006-5-17 8:9:18'
group by ps2.page_id, ps2.template_component_id

When run through EXPLAIN ANALYZE, it shows:

                                                           QUERY PLAN 
-------------------------------------------------------------------------------------------------------------------------------
  HashAggregate  (cost=2613.28..2614.17 rows=72 width=16) (actual time=976.629..976.938 rows=128 loops=1)
    ->  Seq Scan on page_schedule ps2  (cost=0.00..2364.95 rows=33110 width=16) (actual time=0.021..623.363 rows=94798 loops=1)
          Filter: (timezone('MST7MDT'::text, start_time) <= '2006-05-17 08:09:18'::timestamp without time zone)
  Total runtime: 977.224 ms
(4 rows)

I've tried doing a function index, like:

create index start_time_page_schedule
           on page_schedule
        using btree ( timezone('MST7MDT'::text, start_time ) );

But, same result ... whereas, if I change the <= to just =, the index is 
used, but that is expected ...

Is there some other way I can either write above query *or* do an index, 
such that it will use the index?

thanks ...

----
Marc G. Fournier           Hub.Org Networking Services (http://www.hub.org)
Email . scrappy@hub.org                              MSN . scrappy@hub.org
Yahoo . yscrappy               Skype: hub.org        ICQ . 7615664



view thread (6+ messages)  latest in thread

Message-ID: <20060520223704.T1114@ganymede.hub.org>
Permalink:  ../20060520223704.T1114@ganymede.hub.org/
Also on:    postgresql.org/message-id/20060520223704.T1114@ganymede.hub.org

 · 

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-sql@postgresql.org
  Cc: scrappy@postgresql.org
  Subject: Re: timestamp query doesn't use an index ...
  In-Reply-To: <20060520223704.T1114@ganymede.hub.org>

* 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