Re: PL/pgSQL functions - text / varchar - havy performance - Mailing list pgsql-performance

From Tom Lane
Subject Re: PL/pgSQL functions - text / varchar - havy performance
Date
Msg-id 28309.1062173915@sss.pgh.pa.us
Whole thread Raw
In response to Re: PL/pgSQL functions - text / varchar - havy performance  (Andrew Sullivan <andrew@libertyrms.info>)
List pgsql-performance
Andrew Sullivan <andrew@libertyrms.info> writes:
> On Fri, Aug 29, 2003 at 11:34:13AM -0400, Bill Moran wrote:
>> Have any explanation as to why that function is so slow?

> Sorry, no.  It might have to do with the planning, though.

Specifically, I'll bet he's getting an indexscan plan with one and not
with the other.  It's just ye olde cross-datatype-comparisons-aren't-
indexable problem.  "varchar = varchar" matches the index on the varchar
column, but "text = text" is a different operator that doesn't match.
Guess which one gets selected when the initial input is "varchar = text".

7.4 has fixed this particular problem by essentially eliminating the
separate operators for varchar, but in prior releases the behavior
Oliver describes is entirely to be expected.  A workaround is to
cast inside the function:

    ... where varcharcolumn = textarg::varchar;

so that "=" gets interpreted as "varchar = varchar".

            regards, tom lane

pgsql-performance by date:

Previous
From: Ken Geis
Date:
Subject: Re: bad estimates
Next
From: Shridhar Daithankar
Date:
Subject: 2.4 v/s 2.6 again.