X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 48A4E3A3E44 for ; Fri, 5 Nov 2004 17:45:50 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 02927-05 for ; Fri, 5 Nov 2004 17:45:46 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id C5F453A3E33 for ; Fri, 5 Nov 2004 17:45:45 +0000 (GMT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.1/8.13.1) with ESMTP id iA5HjYNo000223 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 5 Nov 2004 10:45:37 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.1/8.13.1) with ESMTP id iA5HjYtr000807; Fri, 5 Nov 2004 10:45:34 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.1/8.13.1/Submit) id iA5HjY2n000806; Fri, 5 Nov 2004 10:45:34 -0700 (MST) (envelope-from mfuhr) Date: Fri, 5 Nov 2004 10:45:34 -0700 From: Michael Fuhr To: Christopher Browne Cc: pgsql-performance@postgresql.org Subject: Re: Checking = with timestamp field is slow Message-ID: <20041105174534.GA685@winnie.fuhr.org> References: <2989532e0411042316566b35f4@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200411/101 X-Sequence-Number: 9055 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/