Re: query with timestamp not using index

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Brian Hirt <bhirt(at)mobygames(dot)com>
Cc: "'Postgresql Performance'" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: query with timestamp not using index
Date: 2004-12-01 22:16:53
Message-ID: 19907.1101939413@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Brian Hirt <bhirt(at)mobygames(dot)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

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Josh Berkus 2004-12-01 22:24:12 Alternatives to Dell?
Previous Message Brian Hirt 2004-12-01 22:09:04 Re: query with timestamp not using index