Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> performance question with function returning object type
I have a function which returns an object type which is just a wrapper
for four native sql types. When I call the function it takes x time,
but if I query the individual values it takes x*4 time like it is
actually calling the function four times. Can anyone explain? In case
that does not make sense, here is an example. This is not my actual
function, but it is a simplified illustration of what is happening:
create or replace type res_util_typ
as object (pct_util number(4),
morn_avail number(4), aftn_avail number(4), eve_avail number(4))
CREATE OR REPLACE PACKAGE ALLAN_PKG AS
function get_utilization return res_util_typ;
END ALLAN_PKG;
/
CREATE OR REPLACE PACKAGE BODY ALLAN_PKG AS function get_utilization return res_util_typ is
retVal res_util_typ; pct_util number(4) := 0; tot_used pls_integer := 0; tot_avail_m pls_integer := 0; tot_avail_a pls_integer := 0; tot_avail_e pls_integer := 0;
select case when count(*) > 9999 then 9999
else count(*)
end into tot_avail_m
from all_objects;
select case when count(*) > 9999 then 9999
else count(*)
end into tot_avail_a
from all_objects;
select case when count(*) > 9999 then 9999
else count(*)
end into tot_avail_e
from all_objects;
retVal := res_util_typ(pct_util, tot_avail_m, tot_avail_a, tot_avail_e);
return retVal;
end;
END ALLAN_PKG;
/
Now, if I just call the function we see the statistics:
set autotrace on
set timing on
select allan_pkg.get_utilization from dual
/
GET_UTILIZATION(PCT_UTIL, MORN_AVAIL, AFTN_AVAIL, EVE_AVAIL)
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE 1 0 TABLE ACCESS (FULL) OF 'DUAL'
Statistics
But if I call it so I can get the individual values from the result, the elapsed time and number of recursive calls and consistent gets are approximately multiplied by 4:
select ru.u.pct_util, ru.u.morn_avail, ru.u.aftn_avail, ru.u.eve_avail
from (select allan_pkg.get_utilization u from dual) ru
/
U.PCT_UTIL U.MORN_AVAIL U.AFTN_AVAIL U.EVE_AVAIL ---------- ------------ ------------ ----------- 9999 9999 9999 9999
Elapsed: 00:00:51.01
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE 1 0 TABLE ACCESS (FULL) OF 'DUAL'
Statistics
I don't understand this -- in the first version of the call, we can see
all the values are there; why does it take four times longer to query
them as individual columns?
Any way to avoid this would be appreciated!
Allan Received on Thu Dec 16 2004 - 10:03:30 CST