Re: Speeding up index scans by truncating timestamp? - Mailing list pgsql-general

From Derrick Rice
Subject Re: Speeding up index scans by truncating timestamp?
Date
Msg-id AANLkTinbvuCznTxpSP3XzuSGRX37yj83BFX0uab-o5O=@mail.gmail.com
Whole thread Raw
In response to Speeding up index scans by truncating timestamp?  (Derrick Rice <derrick.rice@gmail.com>)
Responses Re: Speeding up index scans by truncating timestamp?  (Michael Glaesemann <grzm@seespotcode.net>)
Re: Speeding up index scans by truncating timestamp?  (Vick Khera <vivek@khera.org>)
List 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

pgsql-general by date:

Previous
From: Emi Lu
Date:
Subject: Re: read and restore deleted record
Next
From: Michael Glaesemann
Date:
Subject: Re: Speeding up index scans by truncating timestamp?