你好,游客 登录 注册 搜索
背景:
阅读新闻

Oracle的SQL Tuning Advisor(STA) 到底做了什么?

[日期:2013-06-08] 来源:CSDN  作者:Robinson [字体:大 中 小]

4、对比优化前后的I/O 开销

a、先测试优化后的I/O cost
hr@CNMMBO> set autot trace stat;
hr@CNMMBO> select /*+ ORDERED */ * from employees e, locations l, departments d
  2  where e.department_id = d.department_id AND l.location_id = d.location_id
  3  and e.employee_id < :bnd;

33 rows selected.

Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
        14  consistent gets
        10  physical reads
          0  redo size
      5362  bytes sent via SQL*Net to client
        514  bytes received via SQL*Net from client
          4  SQL*Net roundtrips to/from client
          1  sorts (memory)
          0  sorts (disk)
        33  rows processed

--上面的Statistics表明优化后的consistent gets为14,physical reads为10

--将sql profile disable,则该profile不会生效
hr@CNMMBO> set autot off; 
hr@CNMMBO> BEGIN
  2    DBMS_SQLTUNE.alter_sql_profile (name => 'hr_profile', attribute_name => 'STATUS', VALUE => 'DISABLED');
  3  END;
  4  /

PL/SQL procedure successfully completed. 

--Author : Robinson
--Blog  : http://blog.csdn.net/robinson_0612

-->查看disable后的状态
hr@CNMMBO> select name,status from dba_sql_profiles where name='hr_profile';

NAME                          STATUS
------------------------------ --------
hr_profile                    DISABLED

hr@CNMMBO> print bnd;

      BND
----------
      133

--下面来查看disable后的统计信息,SQL语句会回到优化之前     
hr@CNMMBO> set autot trace stat;
hr@CNMMBO> select /*+ ORDERED */ * from employees e, locations l, departments d
  2  where e.department_id = d.department_id AND l.location_id = d.location_id
  3  and e.employee_id < :bnd;

33 rows selected.

Statistics
----------------------------------------------------------
          9  recursive calls
          0  db block gets
        27  consistent gets
          5  physical reads
          0  redo size
      5403  bytes sent via SQL*Net to client
        514  bytes received via SQL*Net from client
          4  SQL*Net roundtrips to/from client
          1  sorts (memory)
          0  sorts (disk)
        33  rows processed

--从上面的统计信息可知,SQL优化之前的consistent gets为27,大于优化之后的consistent gets
--注,此处未对比physical reads,一般情形下我们考虑的是consistent gets,如果需要两个都对比,应每次执行SQL前flush buffer cache

-->接下来可以移除sql profile
hr@CNMMBO> set autot off;
hr@CNMMBO> exec dbms_sqltune.drop_sql_profile('hr_profile');

PL/SQL procedure successfully completed.       

linux
相关资讯       SQL Tuning Advisor 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款