From: Michael Fuhr <mike@fuhr.org>
To: Christopher Browne <cbbrowne@acm.org>
Cc: pgsql-performance@postgresql.org
Subject: Re: Checking = with timestamp field is slow
Date: Fri, 5 Nov 2004 10:45:34 -0700
Message-ID: <20041105174534.GA685@winnie.fuhr.org> (raw)
In-Reply-To: <m3zn1wsbr9.fsf@knuth.knuth.cbbrowne.com>
References: <2989532e0411042316566b35f4@mail.gmail.com>
<m3zn1wsbr9.fsf@knuth.knuth.cbbrowne.com>
On Fri, Nov 05, 2004 at 07:47:54AM -0500, Christopher Browne wrote:
>
> How about changing the criterion to:
>
> where today between '2004-11-05' and '2004-11-06';
>
> That ought to make use of the index on "today".
Yes it should, but it'll also return records that have a "today"
value of '2004-11-06 00:00:00' since "x BETWEEN y AND z" is equivalent
to "x >= y AND x <= z". Try this instead:
WHERE today >= '2004-11-05' AND today < '2004-11-06'
In another post I suggested creating an index on DATE(today). The
above query should make that unnecessary, although in 8.0 such an
index would be used in queries like this:
WHERE today IN ('2004-09-01', '2004-10-01', '2004-11-01');
--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
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-performance@postgresql.org
Cc: mike@fuhr.org, cbbrowne@acm.org
Subject: Re: Checking = with timestamp field is slow
In-Reply-To: <20041105174534.GA685@winnie.fuhr.org>
* 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