SQL> show parameter session_ca
NAME TYPE
------------------------------------ ---------------------
VALUE
------------------------------
session_cached_cursors integer
20
默认为20
执行下面的一段代码,向t表中插入100次99。
SQL> begin
2 for i in 1 .. 100 loop
3 insert into t values (99);
4 end loop;
5 end;
6 /
PL/SQL 过程已成功完成。
查看TKPROF
begin
for i in 1 .. 100 loop
insert into t values (99);
end loop;
end;
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.06 0.04 0 0 0 1
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 2 0.06 0.04 0 0 0 1
Misses in library cache during parse: 0 --没有硬解析 因为刚才执行过这段代码 已经被缓存
Optimizer mode: FIRST_ROWS
Parsing user id: 81
********************************************************************************
INSERT INTO T
VALUES
(99)
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0 -- 软解析只用了1次
Execute 100 0.00 0.00 0 1 106 100
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 101 0.00 0.00 0 1 106 100
Misses in library cache during parse: 0 --没有硬解析
Optimizer mode: FIRST_ROWS
Parsing user id: 81 (recursive depth: 1)
SQL> alter session set session_cached_cursors=0; --禁用该参数
会话已更改。
SQL> begin
2 for i in 1 .. 100 loop
3 insert into t values (99);
4 end loop;
5 end;
6 /
PL/SQL 过程已成功完成。
begin
for i in 1 .. 100 loop
insert into t values (99);
end loop;
end;
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.07 0.08 0 0 0 1
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 2 0.07 0.08 0 0 0 1
Misses in library cache during parse: 0
Optimizer mode: FIRST_ROWS
Parsing user id: 81
********************************************************************************
INSERT INTO T
VALUES
(99)
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 100 0.00 0.00 0 0 0 0 --发现软解析变成了100
Execute 100 0.03 0.00 0 100 303 100
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 200 0.03 0.00 0 100 303 100
Misses in library cache during parse: 0
Optimizer mode: FIRST_ROWS
Parsing user id: 81 (recursive depth: 1)
session_cached_cursors可以缓存PL/SQL中的SQL语句,能够减小服务器软解析的开销。
在《oracle性能诊断艺术》中,可以用下面的sql语句得到些统计信息
SQL> select distinct sid from v$mystat;
SID
----------
158
SQL> select sn.name, ss.value
2 from v$statname sn, v$sesstat ss
3 where sn.statistic# = ss.statistic#
4 and sn.name in ('session cursor cache hits','session cursor cache count','p
arse count (total)')
5 and ss.sid = 158;
NAME VALUE
--------------------------------- ----------
session cursor cache hits 46 --有多少次因为缓存被优化
session cursor cache count 19 --实际缓存的游标数目
parse count (total) 87 --总解析次数
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/25361369/viewspace-711039/
,如需转载,请注明出处,否则将追究法律责任。