摘录Performance Tuning Guide中的原文:
![](http://img.blog.itpub.net/blog/attachment/201501/16/29047826_14214218928HtI.png?x-oss-process=style/bb)
通常情况下,仅仅常量不同(121,247)的两个SQL语句也不能使用相同的shared SQL area。尽管前面每个字符、每个空格都相同也不行。本次试验采用scott用户下的emp表作为测试对象,分别执行下面的两条SQL语句,比较一下解析次数来证实这个论点。
select * from scott.emp where empno=7369;
select * from scott.emp where empno=7499;
1. 查看当前的cursor_sharing状态,EXACT不会影响测试结果,这一点很重要。
SYS@snow >
show parameter cursor_sharing
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
cursor_sharing string
EXACT
2. 执行SQL语句后查看硬解析次数
CLASS=64为SQL
![](http://img.blog.itpub.net/blog/attachment/201501/16/29047826_14214219129q7s.png?x-oss-process=style/bb)
parse count(hard)字段代表系统应解析的次数,并且说明应解析消耗很大(very expensive)
![](http://img.blog.itpub.net/blog/attachment/201501/16/29047826_1421421923P950.png?x-oss-process=style/bb)
注意v$sysstat视图中的 parse count(hard)表示当前系统中SQL应解析的次数,观看其变化。
第一次执行empno=7369的SQL查询,当前硬解析次数为2267
SYS@snow >col name for a30
SYS@snow >
select * from scott.emp where empno=7369;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
7369 SMITH CLERK 7902 17-DEC-80 800 20
SYS@snow >
select * from v$sysstat where name ='parse count (hard)';
STATISTIC# NAME CLASS VALUE STAT_ID
---------- ------------------------------ ---------- ---------- ----------
339 parse count (hard) 64
2267
143509059
重复执行empno=7369的SQL查询,硬解析次数不变
SYS@snow >
select * from scott.emp where empno=7369;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
7369 SMITH CLERK 7902 17-DEC-80 800 20
SYS@snow >select * from v$sysstat where name ='parse count (hard)';
STATISTIC# NAME CLASS VALUE STAT_ID
---------- ------------------------------ ---------- ---------- ----------
339 parse count (hard) 64
2267
143509059
第一次执行empno=7499,由于常量变化引起硬解析
SYS@snow >
select * from scott.emp where empno=7499;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
SYS@snow >
select * from v$sysstat where name ='parse count (hard)';
STATISTIC# NAME CLASS VALUE STAT_ID
---------- ------------------------------ ---------- ---------- ----------
339 parse count (hard) 64
2268
143509059
重复执行empno=7499,采用library cache中已经保存的对象,不再产生硬解析
SYS@snow >
select * from v$sysstat where name ='parse count (hard)';
STATISTIC# NAME CLASS VALUE STAT_ID
---------- ------------------------------ ---------- ---------- ----------
339 parse count (hard) 64
2268
143509059
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29047826/viewspace-1404734/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29047826/viewspace-1404734/