Re: Optimization with dates

From: caldodge(at)fpcc(dot)net (Calvin Dodge)
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Optimization with dates
Date: 2001-11-21 00:28:41
Message-ID: ca6275f0.0111201628.6d3bda77@posting.google.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

cat(at)thefreecat(dot)org (Jean-Christophe Boggio) wrote in message news:<72319017913(dot)20011114005656(at)thefreecat(dot)org>...

> I have tried :
> where dategain>=(select now()-30);
> where dategain+30>='now'
> where date(dategain)>=date('now')-30
> and many other, syntactically absurd :-)
>
> Anyone can help me use this index ?

From my brief experiments, it _looks_ like the optimizer uses index
scan on dates only when those dates are constant (in my case, anyway -
as always, YMMV).

I tried functions, variables, and using both upper and lower limits.

The only time index scanning was used (according to "explain") was
when I used constant values for the dates.

So ... do you _have_ to do your querying in psql? Or will your
application permit you to create queries with embedded constant date
values in the Planguage (PHP, Python, Perl) of your choice?

Calvin

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message David Stanaway 2001-11-21 02:07:02 Re: Postmaster will not start???
Previous Message Merrill Oveson 2001-11-21 00:15:57 bug, I think