Re: SQL function inlining (was: View vs function) - Mailing list pgsql-performance

From Tom Lane
Subject Re: SQL function inlining (was: View vs function)
Date
Msg-id 7635.1111596928@sss.pgh.pa.us
Whole thread Raw
In response to SQL function inlining (was: View vs function)  ("Tambet Matiisen" <t.matiisen@aprote.ee>)
Responses clear function cache (WAS: SQL function inlining)
List pgsql-performance
"Tambet Matiisen" <t.matiisen@aprote.ee> writes:
> I observed slowdowns when I declared SQL function as strict. There were
> no slowdowns, when I implmented the same function in plpgsql, in fact it
> got faster with strict, if parameters where NULL. Could it be
> side-effect of SQL function inlining? Is there CASE added around the
> function to not calculate it, when one of the parameters is NULL?

IIRC we will not inline a STRICT SQL function if the resulting
expression would not behave strict-ly.  This is clearly a necessary rule
because inlining would change the behavior otherwise.  But the test for
it is pretty simplistic: CASEs are considered not strict, period.  So I
think you are measuring the difference between inlined and not-inlined.

I'd suggest just leaving off the STRICT if you are writing a SQL
function you hope to have inlined.

            regards, tom lane

pgsql-performance by date:

Previous
From: Richard Huxton
Date:
Subject: Re: best practices with index on varchar column
Next
From: Andrew Sullivan
Date:
Subject: Re: PostgreSQL on Solaris 8 and ufs