|
A: Согласно документации,
Recursive SQL: When a DDL statement is issued, Oracle implicitly issues
recursive SQL statements that modify data dictionary information. Users need
not be concerned with the recursive SQL internally performed by Oracle.
Вопросов вроде нет, все понятно.
Но анализируя отчет statspack я обнаружил
бешенное кол-во этих самых 'recursive calls'. С
чего бы это ? Одна из возможных причин -
управление местом (extent management), но табличные
пространства - локальные (local management).
Оказалось (благодаря Алексею
Козлову и Тому Кайту), что в статистику
recursive calls включаются все sql, выполнявшиеся
внутри pl/sql кода.
Делаем несложный код:
set serveroutput on;
create or replace function stats return number
is
v_result number;
begin
select b.value into v_result from v$statname a, v$mystat b
where a.statistic# = b.statistic# and lower(a.name) = 'recursive calls';
return v_result;
end;
/
create or replace procedure p
is
v varchar2(1);
begin
dbms_output.put_line ('Before ' || stats);
FOR i IN 1..99 LOOP
select 'x' into v from dual;
END LOOP;
dbms_output.put_line ('After ' || stats);
end;
/
alter session set sql_trace=true;
exec p;
Честно видим в output'е что кол-во recursive calls
увеличилось на 100. В ужасе залезаем в trace
файл, видим там
SELECT 'x' from dual
END OF STMT
PARSE #3:c=0,e=1456,p=0,cr=0,cu=0,mis=1,r=0,dep=1,og=4,tim=2858053838
EXEC #3:c=0,e=115,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=4,tim=2858055041
FETCH #3:c=0,e=169,p=0,cr=3,cu=0,mis=0,r=1,dep=1,og=4,tim=2858055455
Важно r=1 напротив Fetch.
Тот же trace файл обработанный с
помошью tkprof
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 2 0.01 0.01 0 0 0 0
Execute 3 0.04 0.06 0 0 0 2
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 5 0.05 0.07 0 0 0 2
Misses in library cache during parse: 2
Misses in library cache during execute: 1
OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 7 0.03 0.07 0 3 0 0
Execute 106 0.02 0.00 0 0 0 0
Fetch 106 0.03 0.02 0 309 0 106
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 219 0.08 0.10 0 312 0 106
106 Recursive Execute.
Так что оказалось что приложение
вызывало в массовом порядке, не отдельные
запросы, а хранимые процедуры. Что не может
не вызвать восхищения. |