Re: timestamp query doesn't use an index ... - Mailing list pgsql-sql

From Tom Lane
Subject Re: timestamp query doesn't use an index ...
Date
Msg-id 5287.1148225462@sss.pgh.pa.us
Whole thread Raw
In response to timestamp query doesn't use an index ...  ("Marc G. Fournier" <scrappy@postgresql.org>)
Responses Re: timestamp query doesn't use an index ...
List pgsql-sql
"Marc G. Fournier" <scrappy@postgresql.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


pgsql-sql by date:

Previous
From: Markus Schaber
Date:
Subject: Re: usernames of a group from SQL
Next
From: "Marc G. Fournier"
Date:
Subject: Re: timestamp query doesn't use an index ...