From: Herouth Maoz <herouth@oumail.openu.ac.il>
To: Michael Richards <miker@scifair.acadiau.ca>
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] indexes using datetime
Date: Mon, 6 Sep 1999 18:25:13 +0300
Message-ID: <l03130306b3f98cc074df@[147.233.159.109]> (raw)
In-Reply-To: <9681.935887600@sss.pgh.pa.us>
References: <Pine.BSF.4.10.9908271904550.29442-100000@scifair.acadiau.ca>
At 03:46 +0300 on 29/08/1999, Tom Lane wrote:
> 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.
A tip: use
SELECT 'now'::datetime - '40 days'::timespan;
Get the result on your client side, say in a variable named $x, and use it
in the "real" query:
SELECT * FROM logins WHERE logintime > $x;
(Actual embedding protocol depends, of course, on the language you use).
Then it's a constant, as far as Postgres is concerned, and the time wasted
for the small query is really not an issue.
Herouth
--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: herouth@oumail.openu.ac.il, miker@scifair.acadiau.ca
Subject: Re: [SQL] indexes using datetime
In-Reply-To: <l03130306b3f98cc074df@[147.233.159.109]>
References: <Pine.BSF.4.10.9908271904550.29442-100000@scifair.acadiau.ca> <l03130306b3f98cc074df@[147.233.159.109]>
* 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