Re: query with timestamp not using index

From: Tom Lane
Subject: Re: query with timestamp not using index
Date: ,
Msg-id: 19907.1101939413@sss.pgh.pa.us
(view: Whole thread, Raw)
In response to: Re: query with timestamp not using index  (Brian Hirt)
List: pgsql-performance

Tree view

query with timestamp not using index  (Brian Hirt, )
 Re: query with timestamp not using index  (Richard Huxton, )
 Re: query with timestamp not using index  (Brian Hirt, )
  Re: query with timestamp not using index  (Tom Lane, )
 Re: query with timestamp not using index  (Tom Lane, )

Brian Hirt <> 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:

From: Geoffrey
Date:
Subject: Re: Alternatives to Dell?
From: Josh Berkus
Date:
Subject: Re: Recommended Specs