Thread: Re: indexing timestamp fields

Re: indexing timestamp fields

From
Christopher Browne
Date:
teknokrat <teknokrat@yahoo.com> 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;
-- 
"cbbrowne","@","libertyrms.info"
<http://dev6.int.libertyrms.com/>
Christopher Browne
(416) 646 3304 x124 (land)


Re: indexing timestamp fields

From
Christopher Browne
Date:
teknokrat <teknokrat@yahoo.com> writes:
> Christopher Browne wrote:
>
>> teknokrat <teknokrat@yahoo.com> 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")
<http://dev6.int.libertyrms.com/>
Christopher Browne
(416) 646 3304 x124 (land)


Re: indexing timestamp fields

From
teknokrat
Date:
Christopher Browne wrote:

> teknokrat <teknokrat@yahoo.com> 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



Re: indexing timestamp fields

From
Bruno Wolff III
Date:
On Wed, Oct 15, 2003 at 21:25:17 +0100, teknokrat <teknokrat@yahoo.com> wrote:
> 
> 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

Unless that query returns only a small fraction of the table (which would
be unusual for a before some date restriction) or you order by the date,
an index probably won't help.