Re: timestamp query doesn't use an index ...

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Marc G(dot) Fournier" <scrappy(at)postgresql(dot)org>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: timestamp query doesn't use an index ...
Date: 2006-05-21 15:31:02
Message-ID: 5287.1148225462@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Marc G. Fournier" <scrappy(at)postgresql(dot)org> writes:
> 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

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

One-sided inequalities frequently *shouldn't* use an index, because
they're retrieving too much of the table. Are you sure this is fetching
only a small fraction of the table? Are you using PG 8.1 (8.1 would be
likely to try to use a bitmap indexscan for this)?

You could experiment with enable_seqscan = off to see if the planner is
actually wrong about its choice. If so, reducing random_page_cost might
be the best permanent solution.

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Marc G. Fournier 2006-05-21 17:08:51 Re: timestamp query doesn't use an index ...
Previous Message Markus Schaber 2006-05-21 10:34:10 Re: usernames of a group from SQL