pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Brian Hirt <bhirt@mobygames.com>
Cc: 'Postgresql Performance' <pgsql-performance@postgresql.org>
Subject: Re: query with timestamp not using index
Date: Wed, 01 Dec 2004 17:16:53 -0500
Message-ID: <19907.1101939413@sss.pgh.pa.us> (raw)
In-Reply-To: <9CFDF39A-43E5-11D9-AD0F-000D93AD2E74@mobygames.com>
References: <95241C28-43B8-11D9-AD0F-000D93AD2E74@mobygames.com>
	<18427.1101931618@sss.pgh.pa.us>
	<9CFDF39A-43E5-11D9-AD0F-000D93AD2E74@mobygames.com>

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



view thread (5+ messages)

Message-ID: <19907.1101939413@sss.pgh.pa.us>
Permalink:  ../19907.1101939413@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/19907.1101939413@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, bhirt@mobygames.com
  Subject: Re: query with timestamp not using index
  In-Reply-To: <19907.1101939413@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox