I am rewriting Sybase view to postgresql and encountered such problem.
Is there any way to improve performance of view with functions inside?
For example we have complex function
create function func1(pid integer) returns char(20) as $$ begin ... do stuf return 'aaaa'; end; $$ language plpgsql;
And create view with function
create view view_client as select code, name, func1(pid) from client;
Such view performs terrible slow, unless "func1" is removed from it. Postgresql probalby executes function for every row even if column is not used?
count(*) from view with 2M rows takes 2+ minutes, without "func1" it takes ~10sec.