Oracle 11g Adaptive Cursor Sharing (ACS)

unstable_plans.sql – this one shows statements that have multiple plans with large variance in execution time
awr_plan_change.sql – history of how the statement plan changes over time
awr_plan_stats.sql – aggregate statement stats (like elapsed_time, lio, etc) grouped by plan
find_sql_acs.sql – A queries v$sql and shows ACS related columns
mismatch3.sql – A variation of Dion Cho’s script to display data from v$sql_shared_cursor (see his post here) 
----------------------------------------------------------------------------------------
--
-- File name:   unstable_plans.sql
--
-- Purpose:     Attempts to find SQL statements with plan instability.
--
-- Author:      Kerry Osborne
--
-- Usage:       This scripts prompts for two values, both of which can be left blank.
--
--              min_stddev: the minimum "normalized" standard deviation between plans
--                          (the default is 2)
--
--              min_etime:  only include statements that have an avg. etime > this value
--                          (the default is .1 second)
--
-- See http://kerryosborne.oracle-guy.com/2008/10/unstable-plans/ for more info.
---------------------------------------------------------------------------------------

set lines 155
col execs for 999,999,999
col min_etime for 999,999.99
col max_etime for 999,999.99
col avg_etime for 999,999.999
col avg_lio for 999,999,999.9
col norm_stddev for 999,999.9999
col begin_interval_time for a30
col node for 99999
break on plan_hash_value on startup_time skip 1
select * from (
select sql_id, sum(execs), min(avg_etime) min_etime, max(avg_etime) max_etime, stddev_etime/min(avg_etime) norm_stddev
from (
select sql_id, plan_hash_value, execs, avg_etime,
stddev(avg_etime) over (partition by sql_id) stddev_etime
from (
select sql_id, plan_hash_value,
sum(nvl(executions_delta,0)) execs,
(sum(elapsed_time_delta)/decode(sum(nvl(executions_delta,0)),0,1,sum(executions_delta))/1000000) avg_etime
-- sum((buffer_gets_delta/decode(nvl(buffer_gets_delta,0),0,1,executions_delta))) avg_lio
from DBA_HIST_SQLSTAT S, DBA_HIST_SNAPSHOT SS
where ss.snap_id = S.snap_id
and ss.instance_number = S.instance_number
and executions_delta > 0
group by sql_id, plan_hash_value
)
)
group by sql_id, stddev_etime
)
where norm_stddev > nvl(to_number(‘&min_stddev‘),2)
and max_etime > nvl(to_number(‘&min_etime‘),.1)
order by norm_stddev
/
----------------------------------------------------------------------------------------
--
-- File name:   awr_plan_change.sql
--
---------------------------------------------------------------------------------------

set lines 155
col execs for 999,999,999
col avg_etime for 999,999.999
col avg_lio for 999,999,999.9
col begin_interval_time for a30
col node for 99999
break on plan_hash_value on startup_time skip 1
select ss.snap_id, ss.instance_number node, begin_interval_time, sql_id, plan_hash_value,
nvl(executions_delta,0) execs,
(elapsed_time_delta/decode(nvl(executions_delta,0),0,1,executions_delta))/1000000 avg_etime,
(buffer_gets_delta/decode(nvl(buffer_gets_delta,0),0,1,executions_delta)) avg_lio
from DBA_HIST_SQLSTAT S, DBA_HIST_SNAPSHOT SS
where sql_id = nvl(‘&sql_id‘,‘4dqs2k5tynk61‘)
and ss.snap_id = S.snap_id
and ss.instance_number = S.instance_number
and executions_delta > 0
order by 1, 2, 3
/
----------------------------------------------------------------------------------------
--
-- File name:   awr_plan_stats.sql
--
---------------------------------------------------------------------------------------
-- Note that I have modified this script slightly to include snaps with 0 executions.
-- This is to account for situations with very long running statements (that generally
-- cross snapshot boundaries). In these situations, the executions_delta is incremented
-- in the snapshot when the statement begins. There will be 0 executions_delta in
-- subsequent snapshots, but the time and lio‘s should still be considered.
set lines 155
col execs for 999,999,999
col etime for 999,999,999.9
col avg_etime for 999,999.999
col avg_cpu_time for 999,999.999
col avg_lio for 999,999,999.9
col avg_pio for 9,999,999.9
col begin_interval_time for a30
col node for 99999
break on plan_hash_value on startup_time skip 1
select sql_id, plan_hash_value,
sum(execs) execs,
-- sum(etime) etime,
sum(etime)/sum(execs) avg_etime,
sum(cpu_time)/sum(execs) avg_cpu_time,
sum(lio)/sum(execs) avg_lio,
sum(pio)/sum(execs) avg_pio
from (
select ss.snap_id, ss.instance_number node, begin_interval_time, sql_id, plan_hash_value,
nvl(executions_delta,0) execs,
elapsed_time_delta/1000000 etime,
(elapsed_time_delta/decode(nvl(executions_delta,0),0,1,executions_delta))/1000000 avg_etime,
buffer_gets_delta lio,
disk_reads_delta pio,
cpu_time_delta/1000000 cpu_time,
(buffer_gets_delta/decode(nvl(buffer_gets_delta,0),0,1,executions_delta)) avg_lio,
(cpu_time_delta/decode(nvl(executions_delta,0),0,1,executions_delta)) avg_cpu_time
from DBA_HIST_SQLSTAT S, DBA_HIST_SNAPSHOT SS
where sql_id = nvl(‘&sql_id‘,‘4dqs2k5tynk61‘)
and ss.snap_id = S.snap_id
and ss.instance_number = S.instance_number
-- and executions_delta > 0
)
group by sql_id, plan_hash_value
order by 5
/
----------------------------------------------------------------------------------------
--
-- File name:   find_sql_acs.sql
--
---------------------------------------------------------------------------------------

set verify off
set pagesize 999
col username format a13
col prog format a22
col sql_text format a35
col sid format 999
col child_number format 99999 heading CHILD
col ocategory format a10
col execs format 9,999,999
col execs_per_sec format 999,999.99
col etime format 9,999,999.99
col avg_etime format 99,999.99
col cpu format 9,999,999
col avg_cpu  format 99,999.99
col pio format 9,999,999
col avg_pio format 99,999.99
col lio format 9,999,999
col avg_lio format 9,999,999
col ibs format a3
col iba format a3
col ish format a3

select sql_id, child_number, plan_hash_value,
is_bind_sensitive ibs,
is_bind_aware iba,
is_shareable ish,
executions execs,
rows_processed ,
-- executions/((sysdate-to_date(first_load_time,‘YYYY-MM-DD/HH24:MI:SS‘))*(24*60*60)) execs_per_sec,
-- elapsed_time/1000000 etime,
(elapsed_time/1000000)/decode(nvl(executions,0),0,1,executions) avg_etime,
-- cpu_time/1000000 cpu,
(cpu_time/1000000)/decode(nvl(executions,0),0,1,executions) avg_cpu,
-- disk_reads pio,
disk_reads/decode(nvl(executions,0),0,1,executions) avg_pio,
-- buffer_gets lio,
buffer_gets/decode(nvl(executions,0),0,1,executions) avg_lio,
sql_text
from v$sql s
where sql_text like nvl(‘&sql_text‘,sql_text)
and sql_text not like ‘%from v$sql where sql_text like nvl(%‘
and sql_id like nvl(‘&sql_id‘,sql_id)
and is_bind_aware like nvl(‘&is_bind_aware‘,is_bind_aware)
order by sql_id, child_number
/
----------------------------------------------------------------------------------------
--
-- File name:   mismatch3.sql
--
---------------------------------------------------------------------------------------
-- Modified version of Dion Cho‘s script - http://dioncho.wordpress.com/?s=v%24sql_shared_cursor
--
-- Modified by Kerry Osborne
-- I just changed the output columns (got rid of sql_text and address columns and added last_load_time)
-- I also ordered the output by last_load_time.
--
declare
  c         number;
  col_cnt   number;
  col_rec   dbms_sql.desc_tab;
  col_value varchar2(4000);
  ret_val    number;
begin
  c := dbms_sql.open_cursor;
  dbms_sql.parse(c,
      ‘select q.sql_text, q.last_load_time, s.*
      from v$sql_shared_cursor s, v$sql q
      where s.sql_id = q.sql_id
          and s.child_number = q.child_number
          and q.sql_id like ‘‘&sql_id‘‘
      order by last_load_time‘,
      dbms_sql.native);
  dbms_sql.describe_columns(c, col_cnt, col_rec);

  for idx in 1 .. col_cnt loop
    dbms_sql.define_column(c, idx, col_value, 4000);
  end loop;

  ret_val := dbms_sql.execute(c);

  while(dbms_sql.fetch_rows(c) > 0) loop
    for idx in 1 .. col_cnt loop
      dbms_sql.column_value(c, idx, col_value);
      if col_rec(idx).col_name in (‘SQL_ID‘, ‘CHILD_NUMBER‘,‘LAST_LOAD_TIME‘) then
        dbms_output.put_line(rpad(col_rec(idx).col_name, 30) ||
                ‘ = ‘ || col_value);
      elsif col_value = ‘Y‘ then
        dbms_output.put_line(rpad(col_rec(idx).col_name, 30) ||
                ‘ = ‘ || col_value);
      end if;

    end loop;

    dbms_output.put_line(‘--------------------------------------------------‘);

   end loop;

  dbms_sql.close_cursor(c);

end;
/

转自《http://kerryosborne.oracle-guy.com/2009/06/oracle-11g-adaptive-cursor-sharing-acs/》

时间: 2024-09-30 14:36:01

Oracle 11g Adaptive Cursor Sharing (ACS)的相关文章

oracle11g新特点——Adaptive Cursor Sharing (ACS)

1.   ACS简介 Oracle Database 11g提供了Adaptive Cursor Sharing (ACS)功能,以克服以往不该共享的游标被共享的可能性.ACS使用两个新指标:sensitivity and bindawareness来实施该特点. 2.   ACS机制 2.1.  Adaptive Cursor Sharing Metadata:Oracle 11g也提供了三个新视图和动态视图V$SQL的两个新列来允许DBA来确定优化器是否已经确定一个SQL语句为一个ACS的候

【Oracle 优化器】自适应游标共享(Adaptive Cursor Sharing)功能

概述 我们知道,由于绑定变量窥视(Bind Peeking)功能,SQL文在进行硬解析(Hard Parse)时,会代入绑定变量的值来估算选择基数(cardinality )并做成执行计划,而相同的SQL文以后在执行过程中,都会共享初次执行时做成的执行计划. 如果表的数据分布不均或者数据倾斜时,用于估算的变量值和以后执行中的用到的变量值估算选择基数(cardinality )差异很大时,通过绑定变量窥视(Bind Peeking)功能做成的执行计划,针对某些变量值的执行可能都是最优的,甚至可能引

11g新特性之自适应游标共享(Adaptive Cursor Sharing)

自适应游标共享会使包含绑定变量的单个语句拥有多个执行计划,所谓自适应是指执行计划会依据绑定变量的具体值而适配一个最适合该值的执行计划. 隐藏参数_optimizer_adaptive_cursor_sharing=TRUE 开启或关闭此特性. 首先:游标是否可以被ACS使用,首先游标必须是绑定变量敏感的游标,也就是说最优的执行计划会依赖于绑定变量具体的值.数据库会监控绑定变量敏感的游标,观察是否不同的执行计划会对不同的绑定变量值有好处. 游标在以下两个条件满足的时候会被标记为绑定变量敏感的游标:

[转]Oracle 11g 新特性 -- SQL Plan Management 示例

目录 一 SPM 说明 相关名词说明 SPM的特点 与profile和outline相比更加灵活的控制手段 SPM使计划真正的稳定 SPM的控制方式 SPM如何捕捉加载执行计划 自动捕捉 批量导入 执行计划的选择过程 执行计划的演化evolution 修改已有的Baseline 相关MOS 文档 二 SPM 示例 自动捕捉 手工捕获执行计划 演化SQL Plan Baselines 完整示例 修改 Plan Baselines 显示SQL Plan Baselines 设置SQL Managem

Oracle 11g Articles

发现一个比较有意思的网站,http://www.oracle-base.com/articles/11g/articles-11g.php Oracle 11g Articles Oracle Database 11g: New Features For Administrators OCP Exam Articles Oracle Database 11g Release 1: Miscellaneous Articles Oracle Database 11g Release 2: Misc

Oracle 11g trace events

oracle的events,是我们在做自己的软件系统时可以借鉴的 Oracle 11g trace eventsORA-10001: control file crash event1ORA-10002: control file crash event2ORA-10003: control file crash event3ORA-10004: block recovery testing - internal errorORA-10005: trace latch operations fo

Oracle 11g数据库详解(2015-1-18更新)

Oracle 11g数据库详解 整理者:高压锅 QQ:280604597 Email:[email protected] 大家有什么不明白的地方,或者想要详细了解的地方可以联系我,我会认真回复的 1   简介 数据库操作主要有以下几步: 1.  启动.停止数据库 2.  连接.断开数据库 3.  创建.修改.删除数据库用户 4.  表空间 5.  新建.修改.删除表 6.  查询.插入.修改.删除表数据 7.  新建.修改.删除视图 8.  新建.修改.删除存储过程 9.  新建.修改.删除触发

Oracle 11g数据库详解(2015-02-28更新)

Oracle 11g数据库详解 整理者:高压锅 QQ:280604597 Email:[email protected] 大家有什么不明白的地方,或者想要详细了解的地方可以联系我,我会认真回复的 1   简介 数据库操作主要有以下几步: 1.  启动.停止数据库 2.  连接.断开数据库 3.  创建.修改.删除数据库用户 4.  表空间 5.  新建.修改.删除表 6.  查询.插入.修改.删除表数据 7.  新建.修改.删除视图 8.  新建.修改.删除存储过程 9.  新建.修改.删除触发

Oracle 11g新特性之--Server Result Cache

Oracle 11g新特性之--Server  Result Cache 一.Server Result Cache说明 Oracle官网的说明,参考: 7.6 Managing the Server and Client  Result Caches http://docs.oracle.com/cd/E11882_01/server.112/e16638/memory.htm#BGBCABED 1.1 概述 SQL 查询结果高速缓存可在数据库内存中对查询结果集和查询碎片启用显式高速缓存.存储