ITPub博客

首页 > 数据库 > Oracle > 常量变化导致parse count (hard)次数增加的小实验

常量变化导致parse count (hard)次数增加的小实验

原创 Oracle 作者:SnowDBA 时间:2015-01-16 23:28:26 0 删除 编辑

摘录Performance Tuning Guide中的原文:



通常情况下,仅仅常量不同(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


parse count(hard)字段代表系统应解析的次数,并且说明应解析消耗很大(very expensive)


注意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博客 ” ,链接:https://blog.itpub.net/29047826/viewspace-1404734/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2014-06-21

  • 博文量
    223
  • 访问量
    1633593