X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id A894CDB6CE for ; Tue, 1 Nov 2005 14:17:46 -0400 (AST) 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 26056-05 for ; Tue, 1 Nov 2005 18:17:44 +0000 (GMT) Received: from chrobd01.vailsys.com (chrobd01.vailsys.com [63.210.102.138]) by svr1.postgresql.org (Postfix) with ESMTP id 1081CDB6F2 for ; Tue, 1 Nov 2005 14:17:43 -0400 (AST) Received: from dfsfbd06.vail (dfsfbd06.vail [192.168.129.190]) by chrobd01.vailsys.com (Postfix) with ESMTP id 1BC174983 for ; Tue, 1 Nov 2005 12:17:43 -0600 (CST) Received: from [192.168.129.86] (dfwddurham.vail [192.168.129.86]) by dfsfbd06.vail (Postfix) with ESMTP id 10DFE5E73 for ; Tue, 1 Nov 2005 12:17:43 -0600 (CST) Message-ID: <4367B16B.2050003@vailsys.com> Date: Tue, 01 Nov 2005 12:18:19 -0600 From: David Durham User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050404) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Index lookup on > and < criteria Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200511/4 X-Sequence-Number: 23256 Apologies if this questions is asked often. I'm doing some select statements based on a timestamp field. I have an index on the field, and when I use the '=' operator the index is used. However, if I use the '>' or '<' operators, then it does a full table scan. I've got around 6 million rows, so I would think that an index scan would be more appropriate. Here are the statements I'm looking at: select * from myTable where myTimeStamp = '10/1/2005'; uses an index. select max(myTimeStamp) from myTable; select * from myTable where myTimeStamp < '10/2/2005'; select * from myTable where myTimeStamp < '10/2/2005' and myTimeStamp >= '10/1/2005'; do not use indexes. Can anyone point me to some info about what's going on? I've started reading through the manual (chapter 13) which I think explains query optimizing, index usage etc. It seems like this would be a common enough problem that it would have a relatively simple solution. Thanks. -Dave