From: | Thomas Pundt <mlists(at)rp-online(dot)de> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Cc: | Richard Ray <rray(at)mstc(dot)state(dot)ms(dot)us> |
Subject: | Re: Query is fast and function is slow |
Date: | 2006-12-07 09:53:01 |
Message-ID: | 200612071053.01287.mlists@rp-online.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Hi,
On Wednesday 06 December 2006 16:44, Richard Ray wrote:
| select count(*) from documents where doc_num = '106973821' and (select
| bit_or(group_access) from mda_groups where group_name in (select groname
| from pg_user,pg_group where usename = 'bbob' and usesysid = any(grolist)
| and (groname ~ '.*owner$' or groname = 'admin'))) & access >
| '0'::bit(100);
|
| returns very fast
|
| If I create function
|
| create or replace function check_for_update_permission(text,text) returns
| boolean as '
| declare
| doc_number alias for $1;
| user alias for $2;
| doc_count integer;
| begin
...
| end;
| ' language 'plpgsql';
|
|
| and run "select check_for_update_permission('106973821','bbob');"
| it returns the correct info but takes several minutes
| Would someone please enlighten me.
| Can you do something like explain analyze on a function
Just a guess: is the column "doc_num" really of type text? Maybe using "text"
in the function lets the planner choose a sequential scan?
I'd try putting a "raise notice '%', explain analyze ..." statement into the
function and check the log file.
Ciao,
Thomas
--
Thomas Pundt <thomas(dot)pundt(at)rp-online(dot)de> ---- http://rp-online.de/ ----
From | Date | Subject | |
---|---|---|---|
Next Message | Richard Ray | 2006-12-07 14:53:31 | Re: Query is fast and function is slow |
Previous Message | Phillip Smith | 2006-12-06 23:02:16 | INSERT DELETE RETURNING |