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

From Tom Lane
Subject Re: Type casting and indexes
Date
Msg-id 20978.1052411107@sss.pgh.pa.us
Whole thread Raw
In response to Type casting and indexes  ("David Olbersen" <DOlbersen@stbernard.com>)
List pgsql-performance
"David Olbersen" <DOlbersen@stbernard.com> writes:
> So it seems that the type conversion is killing the use of the index, even though the type conversion has to happen
forthe condition to be tested. 

Seems like I just answered this yesterday ;-)

Note the difference in the number of estimated rows in the two explains.
The reason is that the timestamptz conversion is not a constant and so
the planner can't get a good estimate of the number of rows that will
satisfy it.  (And the reason it's not a constant is that it depends on
SET TIMEZONE.)

Bottom line: declare the constant correctly.  Or at least don't
gratuitously cast it to the wrong thing.

            regards, tom lane


pgsql-performance by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: Type casting and indexes
Next
From: "scott.marlowe"
Date:
Subject: Re: [SQL] Unanswered Questions WAS: An unresolved performance