Re: Type casting and indexes - Mailing list pgsql-performance

From Tom Lane
Subject Re: Type casting and indexes
Date
Msg-id 17013.1052433314@sss.pgh.pa.us
Whole thread Raw
In response to Re: Type casting and indexes  (Stephan Szabo <sszabo@megazone23.bigpanda.com>)
List pgsql-performance
Stephan Szabo <sszabo@megazone23.bigpanda.com> writes:
> On Thu, 8 May 2003, David Olbersen wrote:
>> So it seems that the type conversion is killing the use of the index,
>> even though the type conversion has to happen for the condition to be
>> tested.

> IIRC, timestamp->timestamptz is not considered to give a constant value
> (ie, is not stable)

No: it is stable, but not immutable, because it depends on SET TIMEZONE.
(Our policy on those is if you change one mid-query, it's unspecified
whether the query will notice or not.)  So the query is potentially
indexable.

The problem here is that instead of seeing a constant, the planner sees
a nonconstant function invocation on the right side of '>', and so it
has to fall back to a default selectivity estimate instead of being able
to extract a reasonable estimate from pg_statistic.  The default
estimate is high enough to discourage an indexscan ...

            regards, tom lane


pgsql-performance by date:

Previous
From: "scott.marlowe"
Date:
Subject: Re: [SQL] Unanswered Questions WAS: An unresolved performance
Next
From: Achilleus Mantzios
Date:
Subject: Re: An unresolved performance problem.