Re: Timestamp indexes (why ">" or "between" does not use index?)

From: "Phoenix Kiula" <phoenix(dot)kiula(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Michael Glaesemann" <grzm(at)seespotcode(dot)net>, "PG-General Mailing List" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Timestamp indexes (why ">" or "between" does not use index?)
Date: 2008-02-16 16:13:32
Message-ID: e373d31e0802160813s78d7534ds71fa6336ba451339@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

This table is vacuumed and analyzed every hour, so yes, it's been
analyzed recently.

These are the EXPLAIN ANALYZE outputs for both the equality condition
and the greater than condition:

orguser=# explain analyze select alias from clientswhere modify_date =
'2008-01-01' ;
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------
Index Scan using new_idx_modify_date on clients (cost=0.00..30.23
rows=8 width=10) (actual time=0.136..0.136 rows=0 loops=1)
Index Cond: (modify_date = '2008-01-01 00:00:00'::timestamp without
time zone)
Total runtime: 0.220 ms
(3 rows)

Time: 2.832 ms

orguser=# explain analyze select alias from clientswhere modify_date >
'2008-01-01' ;
QUERY PLAN
------------------------------------------------------------------------------------------------------------------
Seq Scan on clients (cost=0.00..237043.09 rows=136617 width=10)
(actual time=0.391..4007.188 rows=148225 loops=1)
Filter: (modify_date > '2008-01-01 00:00:00'::timestamp without time zone)
Total runtime: 4539.242 ms
(3 rows)

Time: 4539.850 ms

Welcome any thoughts. Thanks!

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2008-02-16 16:15:31 Re: SELECT CAST(123 AS char) -> 1
Previous Message Tom Lane 2008-02-16 16:01:11 Re: Strict-typing benefits/costs