Re: Mystery function error - Mailing list pgsql-sql

From Tom Lane
Subject Re: Mystery function error
Date
Msg-id 10187.1064773754@sss.pgh.pa.us
Whole thread Raw
In response to Re: Mystery function error  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Mystery function error  (Josh Berkus <josh@agliodbs.com>)
List pgsql-sql
I said:
> [hmm, I wonder why plpgsql seems to have gotten slower in 7.4...]

False alarm --- or at least, it wasn't plpgsql's fault.  I copied Joe's
function definition, which was

CREATE OR REPLACE FUNCTION public.locate(bpchar, bpchar) RETURNS int4 AS '

But since position() takes arguments of type TEXT, there are two
bpchar->text coercions involved inside the function.  This was a "free"
binary coercion in 7.3, but 7.4 interprets it as invoking rtrim().
The extra rtrim operations account for most of the slowdown.

Using functions declared like "locate(text, text)" to avoid the unwanted
type coercions, I get these kinds of numbers:
    7.4        7.3

position()    1 usec/call    1 usec/call
SQL func    1 usec/call    90 usec/call
plpgsql func    110 usec/call    100 usec/call
        regards, tom lane


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: Mystery function error
Next
From: "Muhyiddin A.M Hayat"
Date:
Subject: SUM() & GROUP BY