Re: Performance of pl/pgsql functions?

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: John R Pierce <pierce(at)hogranch(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Performance of pl/pgsql functions?
Date: 2012-09-14 13:10:59
Message-ID: CAHyXU0xvt9xMp+wwe-93rW7GKQPCx1v5uHMNMfeAjJO9+32wxg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Sep 14, 2012 at 1:47 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
> 2012/9/14 John R Pierce <pierce(at)hogranch(dot)com>:
>> On 09/13/12 10:17 PM, Wells Oliver wrote:
>>>
>>> Do these tend to perform well? I have some simple formulas in functions
>>> like so:
>>
>>
>> if you code your function in SQL instead of plpgsql, and mark it immutable,
>> it can be inlined by the planner.
>
> you don't need to mark SQL functions - it is not black box for
> optimizer and usually better is don't mark SQL functions.

on my workstation:
OP's plpgsql: 63us / call
1-line plpgsql: 43us / call
1-line sql: 38us / call (marking didn't appear to matter in this case)
manually inlined sql: 38us/call

query was tested via:
explain analyze select stat_foo(v,v,v) from generate_series(1,100000) v;

merlin

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Albe Laurenz 2012-09-14 13:22:02 Re: SQLSTATE[08006] [7] server closed the connection unexpectedly
Previous Message Yvon Thoraval 2012-09-14 13:09:54 SQLSTATE[08006] [7] server closed the connection unexpectedly