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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Michael Glaesemann <grzm(at)seespotcode(dot)net>
Cc: "Phoenix Kiula" <phoenix(dot)kiula(at)gmail(dot)com>, "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 15:39:39
Message-ID: 19464.1203176379@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Michael Glaesemann <grzm(at)seespotcode(dot)net> writes:
> The planner will choose a seq scan if it thinks that it will be
> faster than using an index: if based on its statistics it thinks a
> large portion of rows will match the criteria, a seq scan may well be
> faster than an index scan.

> Have you analyzed recently?

If you've never analyzed at all, the default assumptions will
discourage the planner from using an indexscan for a one-sided
inequality condition (like "x > constant"). On the other hand,
it usually will use an indexscan for a range inequality (like
"x > constant1 and x < constant2", or a BETWEEN construct).

If you do have ANALYZE stats then it all depends on what fraction of
the column's range is selected by the inequality or range condition.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2008-02-16 15:47:24 Re: SELECT CAST(123 AS char) -> 1
Previous Message Arturo Pérez 2008-02-16 15:38:56 nntp interface not working?