Re: query with timestamp not using index - Mailing list pgsql-performance

From Tom Lane
Subject Re: query with timestamp not using index
Date
Msg-id 19907.1101939413@sss.pgh.pa.us
Whole thread Raw
In response to Re: query with timestamp not using index  (Brian Hirt <bhirt@mobygames.com>)
List pgsql-performance
Brian Hirt <bhirt@mobygames.com> writes:
> it's more like:

> declare
>     foo_date date;
> begin
>     select some_date into foo_date from some_table where something = something_else;
>     select blah from redir_log where redir_timestamp >= foo_date::timestamp without time zone at time zone 'GMT';
>     etc / etc / etc

Ah.  In that case you're going to have trouble anyway with the planner
having no clue what the effective value of the comparison expression is,
because it'll certainly not be able to fold the plpgsql variable to a
constant.  I agree with the other person who suggested faking it out
by adding a dummy other-side-of-the-range constraint, perhaps
    AND redir_timestamp <= now()
(or whatever upper bound is okay for your purposes).  This should coax
it into using an indexscan.

            regards, tom lane

pgsql-performance by date:

Previous
From: Brian Hirt
Date:
Subject: Re: query with timestamp not using index
Next
From: Josh Berkus
Date:
Subject: Alternatives to Dell?