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 . [EMAIL PROTECTED]                              MSN . [EMAIL PROTECTED]
Yahoo . yscrappy               Skype: hub.org        ICQ . 7615664

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

              http://archives.postgresql.org

Reply via email to