Oracle SQL Performance Analyzer的使用

通过 SPA,您可以根据各种更改类型(如初始化参数更改、优化器统计刷新和数据库升级)播放特定的 SQL 或整个 SQL 负载,然后生成比较报告,帮助您评估它们的影响。

在 Oracle Database 11g 之前的版本中,我必须捕获所有 SQL 语句,通过跟踪运行这些语句, 然后得到执行计划 — 这是一项极其耗时又极易出错的任务。新版本中,我们不需要再那样做了, 我改用非常简单而有效的 SQL Performance Analyzer。

update t1 set sname='苏州' where sid=500001;
 
update t1 set sname='南京' where sid=600001;

---3.收集统计信息
 
exec dbms_stats.gather_table_stats(USER,'T1',CASCADE=>TRUE)
 

alter system flush shared_pool;
 
---4.执行查询
 
select count(*) from t1 where sid<=100;
 

select count(*) from t1 where sid<=500;
 

select count(*) from t1 where sid>50000;
 

---5.新建STS
 
BEGIN
  DBMS_SQLTUNE.DROP_SQLSET(
    sqlset_name => 'OCPYANG_STS'
    );
 END;
 /
 
BEGIN
  DBMS_SQLTUNE.CREATE_SQLSET(
    sqlset_name => 'OCPYANG_STS',
    sqlset_owner => 'SYS',
    description  => 'ocpyangtest');
 END;
 /
 

---6.加载sql优化集
 
set serveroutput on
 DECLARE
cur01 dbms_sqltune.sqlset_cursor;
 BEGIN
open cur01 for select value(a) from table(dbms_sqltune.select_cursor_cache
 (
 basic_filter => 'sql_text like ''%T1%'' and parsing_schema_name =''SYS''',
 attribute_list => 'ALL'
 )
 ) a;
dbms_sqltune.load_sqlset(
 sqlset_name => 'OCPYANG_STS',
 populate_cursor => cur01);
 close cur01;
 END;
/
 
/*********有两个参数值得特别说明:
 
1)SELECT_CURSOR_CACHE的第一个参数是basic_filter ,它可以取的值有:
 
  sql_id                  VARCHAR(13),
  force_matching_signature NUMBER,
  sql_text                CLOB,
  object_list              sql_objects,
  bind_data                RAW(2000),
  parsing_schema_name      VARCHAR2(30),
  module                  VARCHAR2(48),
  action                  VARCHAR2(32),
  elapsed_time            NUMBER,
  cpu_time                NUMBER,
  buffer_gets              NUMBER,
  disk_reads              NUMBER,
  direct_writes            NUMBER,
  rows_processed          NUMBER,
  fetches                  NUMBER,
  executions              NUMBER,
  end_of_fetch_count      NUMBER,
  optimizer_cost          NUMBER,
  optimizer_env            RAW(1000),
  priority                NUMBER,
  command_type            NUMBER,
  first_load_time          VARCHAR2(19),
  stat_period              NUMBER,
  active_stat_period      NUMBER,
  other                    CLOB,
  plan_hash_value          NUMBER,
  sql_plan                sql_plan_table_type,
  bind_list                sql_binds
 
2)SELECT_CURSOR_CACHE的最后一个参数是attribute_list
 
BASIC (default) -all attributes (such as execution statistics and binds) are returned except the plans The execution context is always part of the result.
 
TYPICAL - BASIC + SQL plan (without row source statistics) and without object reference list
 
ALL - return all attributes
 
Comma separated list of attribute names this allows to return only a subset of SQL attributes: EXECUTION_STATISTICS, BIND_LIST, OBJECT_LIST, SQL_PLAN,SQL_PLAN_STATISTICS: similar to SQL_PLAN + row source statistics
 
*********/

相关推荐