pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Pavel Hlavnicka <pavel@gingerall.cz>
To: pgsql-sql@postgresql.org
Subject: calculated expressions and index use
Date: Thu, 30 Jan 2003 16:54:14 +0100
Message-ID: <3E394AA6.8080400@gingerall.cz> (raw)

Hi all,

I use simple sql statement like this

select * from foo
where created_at >= 'now'::timestamp - '1 hour'::interval;

My table is indexed on created_at field. The query above doesn't use it, 
but if I use

select * from foo where created_at >= 'now'

the index is used.

It looks like if the engine finds some expression to be evaluated it 
gets rid of any index use (due the possible dependency?).

Is it possible to do something to 'precompute' some value in the query 
condition, so planner understand is as a constant value?

(... and I've got some reason NOT to use a parameter in my Perl DBI code...)

Maybe my conclusions are wrong, of course.

Thank you very much in advance

Pavel

-- 
Pavel Hlavnicka
Ginger Alliance
www.gingerall.com




view thread (6+ messages)  latest in thread

Message-ID: <3E394AA6.8080400@gingerall.cz>
Permalink:  ../3E394AA6.8080400@gingerall.cz/
Also on:    postgresql.org/message-id/3E394AA6.8080400@gingerall.cz

 · 

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-sql@postgresql.org
  Cc: pavel@gingerall.cz
  Subject: Re: calculated expressions and index use
  In-Reply-To: <3E394AA6.8080400@gingerall.cz>

* 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