Re: Speeding up index scans by truncating timestamp?

From: Derrick Rice <derrick(dot)rice(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Speeding up index scans by truncating timestamp?
Date: 2011-02-15 15:00:23
Message-ID: AANLkTinbvuCznTxpSP3XzuSGRX37yj83BFX0uab-o5O=@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

>
> Would creating an index on the timestamp truncated to the *day* make the
> index more efficient for queries which are interested in events falling in a
> range of 7+ days?
>

I gave this a shot, changing the index to be on date_trunc('day',
timestamp). PostgreSQL (8.2) then decided not to use the index at all. Not
sure if this is a limitation of PostgreSQL or if it decided it was going to
be more expensive than the alternative.

Is the query optimizer capable of using the relationship between an index on
date_trunc(foo) and a query with "where foo < bar and foo > baz" ? At this
point the question is to satisfy my own curiosity.

Derrick

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Michael Glaesemann 2011-02-15 15:16:37 Re: Speeding up index scans by truncating timestamp?
Previous Message Luca Ferrari 2011-02-15 14:49:35 help understanding explain output