X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 15175D1B503 for ; Wed, 15 Oct 2003 22:13:01 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 42498-09 for ; Wed, 15 Oct 2003 19:12:31 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by svr1.postgresql.org (Postfix) with ESMTP id 60B93D1B510 for ; Wed, 15 Oct 2003 19:12:29 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.12.9/8.12.9) with ESMTP id h9FMCSNu027522 for ; Wed, 15 Oct 2003 22:12:28 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id h9FMA1j5027311 for pgsql-sql@postgresql.org; Wed, 15 Oct 2003 22:10:01 GMT From: Christopher Browne X-Newsgroups: comp.databases.postgresql.sql Subject: Re: indexing timestamp fields Date: Wed, 15 Oct 2003 17:31:21 -0400 Organization: Hub.Org Networking Services Lines: 37 Message-ID: <607k36w5li.fsf@dev6.int.libertyrms.info> References: <60wub6wjxf.fsf@dev6.int.libertyrms.info> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@news.hub.org User-Agent: Gnus/5.1003 (Gnus v5.10.3) XEmacs/21.4 (Reasonable Discussion, linux) Cancel-Lock: sha1:FMYEIigJBx7t8h6UYIU8FIDDMxA= To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/181 X-Sequence-Number: 15581 teknokrat writes: > Christopher Browne wrote: > >> teknokrat writes: >> >>>Is it a good idea to index timestamp fields? what about date fields in >>>general? >> If you need to order by a timestamp, then it can be worthwhile. >> If that timestamp can be null, and is rarely populated, then you >> might >> get a _big_ benefit from creating a partial index as with: >> create index by_some_date on my_table(some_date) where some_date is >> not null; > > I have a lot of queries of the " where timestamp < some date " type > and was wondering if an index would improve performance. None of the > timestamps are null and they are always populated There isn't a single straight answer on this. It _might_ help; it might not. - It might be that adding "timestamp" to some existing index would be better still. - If the table is real big, and the "ts < other_ts" doesn't restrict things very much, then you may merely sit in between an index scan that touches every page of the table and a Seq Scan that does the same. Try creating the index, and do some EXPLAIN ANALYZE queries to see what happens; that should give you an idea as to how effective this is. -- output = ("cbbrowne" "@" "libertyrms.info") Christopher Browne (416) 646 3304 x124 (land)