Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 936E4475A06 for ; Thu, 6 Jun 2002 13:01:47 -0400 (EDT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) by postgresql.org (Postfix) with ESMTP id 460BB475B7F for ; Thu, 6 Jun 2002 13:01:38 -0400 (EDT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 94571D600; Thu, 6 Jun 2002 10:01:37 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 7FF975C01; Thu, 6 Jun 2002 10:01:37 -0700 (PDT) Date: Thu, 6 Jun 2002 10:01:37 -0700 (PDT) From: Stephan Szabo To: Josh Berkus Cc: Andre Schubert , Subject: Re: Indexing timestamps In-Reply-To: Message-ID: <20020606095611.A27330-100000@megazone23.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Archive-Number: 200206/57 X-Sequence-Number: 8022 On Thu, 6 Jun 2002, Josh Berkus wrote: > Andre, > > I'm not even going to try to deal with the seq_scan vs. index_scan > issues on now(). This has been brought up in the list archives. Test > your actual response times as well as the query plan; you may find that > you don't have a real problem. > > Something I can help you with: > > > explain select * from test_table where date_trunc('month',time_stamp) > > = date_trunc('month',datetime('2002-01-01')); > > NOTICE: QUERY PLAN: > > > > Seq Scan on test_table (cost=0.00..2441.41 rows=584 width=16) > > Try doing a: > CREATE INDEX idx_test_month ON test_table(extract(month FROM > time_stamp)); > > Which should help. Unfortunately you can't do that in that sort of syntax. You'll need to create a function that returns the month and is marked as iscachable and use that function in the index creation and query.