关于 cursor_sharing = similar

原创 2004年07月12日 11:29:00


我们先看看在表没有分析无统计数据情况下的表现 

SQL> alter session set cursor_sharing = similar;
 
Session altered.

SQL> select name,value from v$sysstat where name like '%parse%';
 
NAME                                                                  VALUE
---------------------------------------------------------------- ----------
parse time cpu                                                         4948
parse time elapsed                                                     4468
parse count (total)                                                  170148
parse count (hard)                                                     1619  (硬分析次数)
parse count (failures)                                                   80
 
SQL> select count(*) from t where object_id = 1000;
 
   COUNT(*)
----------
          0
 
SQL> select name,value from v$sysstat where name like '%parse%';
 
NAME                                                                  VALUE
---------------------------------------------------------------- ----------
parse time cpu                                                         4948
parse time elapsed                                                     4468
parse count (total)                                                  170172
parse count (hard)                                                     1620
parse count (failures)                                                   80
 
SQL> /
 
NAME                                                                  VALUE
---------------------------------------------------------------- ----------
parse time cpu                                                         4948
parse time elapsed                                                     4468
parse count (total)                                                  170176
parse count (hard)                                                     1620
parse count (failures)                                                   80
 
SQL> select count(*) from t where object_id = 1000;
 
   COUNT(*)
----------
          0
 
SQL> select name,value from v$sysstat where name like '%parse%';
 
NAME                                                                  VALUE
---------------------------------------------------------------- ----------
parse time cpu                                                         4948
parse time elapsed                                                     4468
parse count (total)                                                  170178
parse count (hard)                                                     1620
parse count (failures)                                                   80
 
SQL> select count(*) from t where object_id = 1001;
 
   COUNT(*)
----------
          0
 
SQL> select name,value from v$sysstat where name like '%parse%';
 
NAME                                                                  VALUE
---------------------------------------------------------------- ----------
parse time cpu                                                         4948
parse time elapsed                                                     4468
parse count (total)                                                  170180
parse count (hard)                                                     1620(即使object_id发生变化依然没有硬解析)
parse count (failures)                                                   80

 

 

我们再来看分析表和字段信息后的表现

SQL> analyze table t1 compute statistics for table for columns object_id;
 
Table analyzed.
 
SQL> select name,value from v$sysstat where name like '%parse%';
 
NAME                                                                  VALUE
---------------------------------------------------------------- ----------
parse time cpu                                                         4973
parse time elapsed                                                     4495
parse count (total)                                                  170982
parse count (hard)                                                     1640
parse count (failures)                                                   80
 
SQL> select count(*) from t1 where object_id = 5000;

 
   COUNT(*)
----------
          0
 
SQL> select name,value from v$sysstat where name like '%parse%';
 
NAME                                                                  VALUE
---------------------------------------------------------------- ----------
parse time cpu                                                         4973
parse time elapsed                                                     4495
parse count (total)                                                  170984
parse count (hard)                                                     1641
parse count (failures)                                                   80
 
SQL> select count(*) from t1 where object_id = 5000;
 
   COUNT(*)
----------
          0
 
SQL> select name,value from v$sysstat where name like '%parse%';
 
NAME                                                                  VALUE
---------------------------------------------------------------- ----------
parse time cpu                                                         4973
parse time elapsed                                                     4495
parse count (total)                                                  171008
parse count (hard)                                                     1641 (重复执行没发生变化)
parse count (failures)                                                   80
 
SQL> select count(*) from t1 where object_id = 5001;
 
   COUNT(*)
----------
          0
 
SQL> select name,value from v$sysstat where name like '%parse%';
 
NAME                                                                  VALUE
---------------------------------------------------------------- ----------
parse time cpu                                                         4973
parse time elapsed                                                     4495
parse count (total)                                                  171010
parse count (hard)                                                     1642 (当object_id变化的时候产生硬分析)
parse count (failures)                                                   80
 
SQL>

SQL> select sql_text,child_number from v$sql where sql_text like 'select count(*) from t1 where%';
 
SQL_TEXT
--------------------------------------------------------------------------------
CHILD_NUMBER
------------
select count(*) from t1 where object_id = :"SYS_B_0"
            0
 
select count(*) from t1 where object_id = :"SYS_B_0"
            1

        可以看出若存在object_id的 histograms ,则每次是不同的  值 的时候都产生硬解析 ,若不存在 histograms ,则不产生硬解析 。换句话说,当表的字段被分析过存在histograms的时候,similar 的表现和exact一样,当表的字段没被分析不存在histograms的时候,similar的表现和force一样。这样避免了一味地如force一样转换成变量形式,因为有hostograms的情况下转换成变量之后就容易产生错误的执行计划,没有利用上统计信息。而exact呢,在没有hostograms的情况下也要分别产生硬解析,这样的话,由于执行计划不会受到数据分布的影响(因为没有统计信息)重新解析是没有实质意义的。而similar则综合了两者的优点。

 

 

 

 

 

 

 

初始化参数之cursor_sharing

原帖地址http://www.cnblogs.com/Richardzhu/archive/2013/01/21/2869837.html 一、Cursor_sharing简介: ...

Oracle 11g 新特性 -- 自适应游标共享(Adaptive Cursor Sharing: ACS) 说明

一.自适应游标共享(Adaptive Cursor Sharing) 说明 1.1 ACS概述绑定变量使Oracle DB 可以为多条SQL 语句共享单个游标,以减少分析SQL 语句所使用的共享内存量...

探秘oracle11g acs (adaptiver cursor sharing)

一、什么是ACS(adaptiver cursor sharing) Oracle通过绑定变量技术解决了SQL语句硬解析过多的问题,降低了资源的争用。但是绑定变量在引入cursor sharing,增...

Use cursor_sharing_exact refused to SQL variable binding

In the use cursor_sharing parameters, may cause some SQL children cursor too high, cause competition...

cursor_sharing参数!

cursor_sharing这个参数用来告诉Oracle在什么情况下可以共享游标,即SQL重用。它有3个值可以设置:CURSOR_SHARING = { SIMILAR | EXACT | FORCE...

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

本文主要介绍Oracle优化器的自适应游标共享(Adaptive Cursor Sharing)功能和处理流程。...

浅谈cursor_sharing取值对SQL共享的影响(上)

声明:本篇实验思路感谢dbsnake老师指点。   在Oracle中,用户应用输入的SQL语句要进行所谓的Parse解析过程,用于生成执行计划,这也就是Query Optimizer的主要工作...

11gR2 新特性之(一)Adaptive Cursor Sharing(ACS)

原文链接 个人博客http://www.killdb.com/?p=55 关于该特性,其实并不是11gR2开始引入的,其实在11gR1就引入了,只不过其问题较多,并未引起太多 关注而已(bug...

oracle11g中SQL优化(SQL TUNING)新特性之Adaptive Cursor Sharing (ACS)

oracle11g中最重要的特点之一——Adaptive Cursor Sharing (ACS),几乎完美的解决了之前版本不绑定不行,绑定也不行的尬尴问题,今天有机会对此特点再次进行研究和查阅资料,...
  • LHDZ_BJ
  • LHDZ_BJ
  • 2015年06月30日 14:10
  • 1022

cursor_sharing的妙用

cursor_sharing的妙用Oracle2009-12-28 10:17:16阅读100评论0  字号:大中小 订阅OLTP系统中,我们总是希望使用绑定变量将sql语句共享在library ca...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:关于 cursor_sharing = similar
举报原因:
原因补充:

(最多只允许输入30个字)