Re: Checking = with timestamp field is slow

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Antony Paul <antonypaul24(at)gmail(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Checking = with timestamp field is slow
Date: 2004-11-05 08:34:01
Message-ID: 20041105083401.GA44953@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Fri, Nov 05, 2004 at 12:46:20PM +0530, Antony Paul wrote:

> I have a table which have more than 200000 records. I need to get
> the records which matches like this
>
> where today::date = '2004-11-05';
>
> This is the only condition in the query. There is a btree index on the
> column today. Is there any way to optimise it.

Is the today column a TIMESTAMP as the subject implies? If so then
your queries probably aren't using the index because you're changing
the type to something that's not indexed. Your queries should speed
up if you create an index on DATE(today):

CREATE INDEX foo_date_today_idx ON foo (DATE(today));

After creating the new index, use WHERE DATE(today) = '2004-11-05'
in your queries. EXPLAIN ANALYZE should show that the index is
being used.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Leeuw van der, Tim 2004-11-05 08:48:00 Re: Restricting Postgres
Previous Message Michael Glaesemann 2004-11-05 08:32:49 Re: Checking = with timestamp field is slow