Re: [SQL] indexes using datetime

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Michael Richards <miker(at)scifair(dot)acadiau(dot)ca>
Cc: pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [SQL] indexes using datetime
Date: 1999-08-29 00:46:40
Message-ID: 9681.935887600@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Michael Richards <miker(at)scifair(dot)acadiau(dot)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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 1999-08-29 01:00:46 Re: [HACKERS] entries in pg_shadow
Previous Message Michael Richards 1999-08-29 00:40:29 entries in pg_shadow