From: Tom Lane <tgl@sss.pgh.pa.us>
To: Jean-Christophe Boggio <cat@thefreecat.org>
Cc: pgsql-sql@postgresql.org
Subject: Re: Optimization with dates
Date: Tue, 13 Nov 2001 21:43:52 -0500
Message-ID: <4596.1005705832@sss.pgh.pa.us> (raw)
In-Reply-To: <72319017913.20011114005656@thefreecat.org>
References: <72319017913.20011114005656@thefreecat.org>
Jean-Christophe Boggio <cat@thefreecat.org> writes:
> I have tried :
> where dategain>=(select now()-30);
> where dategain+30>='now'
> where date(dategain)>=date('now')-30
> and many other, syntactically absurd :-)
Try
dategain >= ago(30)
where "ago" is a function that computes "date(now()) - n" and is
marked "iscachable". This is a cheat but it keeps the planner from
being distracted by the noncachable nature of "now()". You can find
past discussions of this if you search the archives for "iscachable",
eg
http://fts.postgresql.org/db/mw/msg.html?mid=1037521http://fts.postgresql.org/db/mw/msg.html?mid=60584http://fts.postgresql.org/db/mw/msg.html?mid=97823
As several other people pointed out, there's also a question of whether
the system *should* use the index --- you haven't told us how many
rows you expect the query to visit. But until you express the WHERE
condition in the form "column >= something-that-can-be-reduced-to-
a-constant", you're unlikely to get the system to even try.
regards, tom lane
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: tgl@sss.pgh.pa.us, cat@thefreecat.org
Subject: Re: Optimization with dates
In-Reply-To: <4596.1005705832@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