Re: Review: prepare plans of embedded sql on function start - Mailing list pgsql-hackers

From Andy Colson
Subject Re: Review: prepare plans of embedded sql on function start
Date
Msg-id 4E6561A8.6000303@squeakycode.net
Whole thread Raw
In response to Re: Review: prepare plans of embedded sql on function start  (Andy Colson <andy@squeakycode.net>)
List pgsql-hackers
On 09/05/2011 05:27 PM, Andy Colson wrote:
> On 09/05/2011 05:04 PM, Andrew Dunstan wrote:
>>
>>
>> On 09/05/2011 05:03 PM, Andy Colson wrote:
>>> Pavel, this patch:
>>>
>>> https://commitfest.postgresql.org/action/patch_view?id=624
>>>
>>> It applied clean and compiled ok, but I cannot get it to work at all.
>>>
>>> $ psql
>>> Timing is on.
>>> psql (9.2devel)
>>> Type "help" for help.
>>>
>>> andy=# set plpgsql.prepare_plans to on_start;
>>> ERROR: unrecognized configuration parameter "plpgsql.prepare_plans"
>>>
>>>
>>
>> Did you add plpgsql to custom_variable_classes? It looks like you might not have. (I'm not sure why plpgsql switch
shouldrequire one, though, especially since we now load plpgsql by default. It might be better just to call it
plpgsql_prepare_on_start.)
>>
>> cheers
>>
>> andrew
>>
>>
>
> Ah, yep, that was the problem, thank you.
>
> -Andy
>


However I still cannot get it to work.

andy=# set plpgsql.prepare_plans to on_start;
SET
Time: 0.123 ms
andy=# show plpgsql.prepare_plans; plpgsql.prepare_plans
----------------------- on_start
(1 row)


andy=# create or replace function test1(a integer) returns integer as $$
andy$# begin
andy$# return b+1;
andy$# end;
andy$# $$ language plpgsql;
CREATE FUNCTION
Time: 16.926 ms
andy=#


Oh... shoot, having gone back and read more closely I realize I didnt understand.  I thought the sql would be checked
oncreate.  That's not the case.
 

This is what I'd hopped it was:

create table junk1 (id serial,code1 integer,
);

create or replace function test2() returns integer as $$
declarex integer;
beginselect bob into x from junk1 where id = 4;return x;
end;
$$ language plpgsql;

I was thinking the create function would immediately return saying, unknown column bob, and not create the function.

So now with the function above, this patch has not helped me at all.  I wont get an error until I exec the function.
Justlike without the patch.
 

I'm not so sure how helpful that is.  What is you use the "if false then ... end if" trick to comment out some old
code? You're sill going to check the tables and fields on every exec?
 

Pavel, is there any way to move all that code to the create function?  But, then that would create a dependency where
thereis not one now.  So that would be bad.
 

How about a new "check function test2()" type of call?  I think having the tables/fields checked just once would be
betterthan checking them over and over on ever single execute.
 

-Andy


pgsql-hackers by date:

Previous
From: "Tomas Vondra"
Date:
Subject: Re: PATCH: regular logging of checkpoint progress
Next
From: David Fetter
Date:
Subject: Re: Couple document fixes