Re: SQL functions vs. PL/PgSQL functions - Mailing list pgsql-performance

From Craig Ringer
Subject Re: SQL functions vs. PL/PgSQL functions
Date
Msg-id 4CB569C4.7010100@postnewspapers.com.au
Whole thread Raw
In response to SQL functions vs. PL/PgSQL functions  ("Reuven M. Lerner" <reuven@lerner.co.il>)
List pgsql-performance
On 13/10/2010 3:30 PM, Reuven M. Lerner wrote:

> My question is whether this is somehow to be expected.  Under what
> conditions will SQL functions be slower than PL/PgSQL functions?

The main cases I can think of:

- Where the SQL function is inlined (PL/PgSQL functions can't be
inlined, some SQL functions can) and the inlining turns out to be a
performance loss rather than a gain.

- Where the PL/PgSQL function was constructing queries dynamically for
EXECUTE ... USING, so each query contained its parameters directly. If
converted to an SQL function (or a PL/PgSQL function using SELECT /
PERFORM instead of EXECUTE ... USING) the planner will make more generic
choices because it doesn't have stats on specific parameter values.
These choices are sometimes not all that great.

Beyond that, I'd have to wait to hear from someone who has more real
knowledge than my hand-waving can provide.

--
Craig Ringer

Tech-related writing at http://soapyfrogs.blogspot.com/

pgsql-performance by date:

Previous
From: "Pierre C"
Date:
Subject: Re: Slow count(*) again...
Next
From: Neil Whelchel
Date:
Subject: Re: Slow count(*) again...