Re: Review: prepare plans of embedded sql on function start

From: Andy Colson <andy(at)squeakycode(dot)net>
To:
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, pavel(dot)stehule(at)gmail(dot)com
Subject: Re: Review: prepare plans of embedded sql on function start
Date: 2011-09-05 23:56:24
Message-ID: 4E6561A8.6000303@squeakycode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 should require 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 on create. 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 $$
declare
x integer;
begin
select 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. Just like 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 there is 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 better than checking them over and over on ever single execute.

-Andy

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message David Fetter 2011-09-06 00:05:10 Re: Couple document fixes
Previous Message Tomas Vondra 2011-09-05 23:52:52 Re: PATCH: regular logging of checkpoint progress