Re: [SQL] indexes using datetime - Mailing list pgsql-sql

From Tom Lane
Subject Re: [SQL] indexes using datetime
Date
Msg-id 9681.935887600@sss.pgh.pa.us
Whole thread Raw
In response to indexes using datetime  (Michael Richards <miker@scifair.acadiau.ca>)
Responses Re: [SQL] indexes using datetime
List pgsql-sql
Michael Richards <miker@scifair.acadiau.ca> writes:
> explain select * from logins where logintime>'now'::datetime-'40
> days'::timespan;
> NOTICE:  QUERY PLAN:
> Seq Scan on logins  (cost=5839.78 rows=44958 width=44)

> Very bad query plan :(

Yah.  It's got nothing to do with datetime though.  Problem is that the
system can only make indexscans work with WHERE clauses of the form
"field op constant" (for "op"s related to the sort ordering of the
index of course).  Your righthand side is not a constant.

Eventually, maybe for 6.6 or 6.7, we will have the smarts in place to
reduce constant expressions to simple constants during preprocessing of
a query.  For now, you are going to have to structure your application to
precompute the value that's going to be compared against index entries.
        regards, tom lane


pgsql-sql by date:

Previous
From: Michael Richards
Date:
Subject: entries in pg_shadow
Next
From: Tom Lane
Date:
Subject: Re: [HACKERS] entries in pg_shadow