Re: procedure takes much more time than its query statement

From: "Sabin Coanda" <s(dot)coanda(at)deuromedia(dot)ro>
To: pgsql-performance(at)postgresql(dot)org
Subject: Re: procedure takes much more time than its query statement
Date: 2011-11-02 08:15:45
Message-ID: j8qu8d$nk3$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Excelent !
You are right
Thanks a lot
Sabin

"Craig Ringer" <ringerc(at)ringerc(dot)id(dot)au> wrote in message
news:4EB0A920(dot)1010209(at)ringerc(dot)id(dot)au(dot)(dot)(dot)
> On 11/01/2011 10:01 PM, Sabin Coanda wrote:
>> Hi there,
>>
>> I have the function:
>> CREATE OR REPLACE FUNCTION "Test"( ... )
>> RETURNS SETOF record AS
>> $BODY$
>> BEGIN
>> RETURN QUERY
>> SELECT ...;
>> END;
>> $BODY$
>> LANGUAGE 'plpgsql' STABLE
>>
>> The function call takes about 5 minute to proceed, but using directly its
>> query statement, after replacing the arguments with the same values, it
>> takes just 5 seconds !
>>
>> I repeat the test several times and the duration is the same.
>>
>> What is wrong ?
>>
> Is it also slow if, outside PL/PgSQL in a regular psql session, you
> PREPARE the query, then EXECUTE it?
>
> If so, you're being bitten by a generic query plan. The server does a
> better job when it knows what parameter is used when it's planning the
> statement. To work around it, you can use the PL/PgSQL 'EXECUTE ... USING
> ...' statement to force a re-plan of the statement for every time it's
> run.
>
> --
> Craig Ringer
>
> --
> Sent via pgsql-performance mailing list (pgsql-performance(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-performance
>

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Yeb Havinga 2011-11-02 13:05:06 Intel 710 pgbench write latencies
Previous Message Mohamed Hashim 2011-11-02 07:12:20 Re: Performance Problem with postgresql 9.03, 8GB RAM,Quadcore Processor Server--Need help!!!!!!!