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.
