dynamically generated SQL and planner/performance

From: Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it>
To: pgsql-general(at)postgresql(dot)org
Subject: dynamically generated SQL and planner/performance
Date: 2008-03-20 15:43:55
Message-ID: 20080320164355.32e9c997@webthatworks.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I've a lot of code that should call different functions according to
values in tables.

something like:

create table FuncName(Name varchar(10), arg int);

insert into FuncName values('ciro',5);
insert into FuncName values('pino',7);
insert into FuncName values('nano',11);

create or replace function ciro(arg int, out res int) as
$$
begin
res:=arg;
return;
end;
$$ language plpgsql;

create or replace function pino(arg int, out res int) as
$$
begin
res:=arg*2;
return;
end;
$$ language plpgsql;

create or replace function nano(arg int, out res int) as
$$
begin
res:=arg*4;
return;
end;
$$ language plpgsql;

create or replace function FBuilder(out res int) as
$$
declare
statement varchar(256);
_Name varchar(10);
_arg int;
begin
select into _Name, _arg Name, arg from FuncName order by random();
statement := ' select * from ' || _Name || '(' || _arg || ')';
execute statement into res;
return;
end;
$$ language plpgsql;

select * from FBuilder();

I don't understand which impact will have on the planner, caching
etc... generating the statement dynamically.

Will the execution of ciro, pino e nano be affected?
Or will just the plan for executing FBuilder statement be affected?

thanks

--
Ivan Sergio Borgonovo
http://www.webthatworks.it

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Josh Trutwin 2008-03-20 16:02:21 ALTER TABLE with USING clause for timestamp
Previous Message Stephan Szabo 2008-03-20 15:17:37 Re: unexpected results with NOT IN query