关于 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 = similar

我们先看看在表没有分析无统计数据情况下的表现  SQL> alter session set cursor_sharing = similar;   Session altered. SQL> s...
  • biti_rainy
  • biti_rainy
  • 2004年07月12日 11:29
  • 11851

初始化参数之cursor_sharing

原帖地址http://www.cnblogs.com/Richardzhu/archive/2013/01/21/2869837.html 一、Cursor_sharing简介: ...
  • freedompuge
  • freedompuge
  • 2016年07月07日 12:01
  • 750

关于cursor_sharing = similar

本文作者: biti_rainy (biti_rainy@itpub.net) 摘要:本文通过简单实验来尝试说明cursor_sharing=similar的含义。1.1.        实验现象我们...
  • emag_oracle
  • emag_oracle
  • 2005年02月01日 16:21
  • 8429

关于cursor_sharing=similar

  • zgqtxwd
  • zgqtxwd
  • 2008年04月26日 15:39
  • 101

Oracle cursor_sharing 参数 详解

一. 官网的说明 http://download.oracle.com/docs/cd/E11882_01/server.112/e17110/initparams042.htm#REFRN1002...
  • xujinyang
  • xujinyang
  • 2011年10月09日 11:24
  • 897

Oracle cursor_sharing 参数 详解

一. 官网的说明http://download.oracle.com/docs/cd/E11882_01/server.112/e17110/initparams042.htm#REFRN10025 ...
  • tianlesoftware
  • tianlesoftware
  • 2011年06月17日 14:24
  • 14609

游标共享之cursor_sharing=similar

cursor_sharing=similar   ,exact和force折中的参数。当探测到谓词会导致执行计划的改变,就会重新解析,否则不会。       适用场景:在无法将应用的代码修改为绑定变量...
  • guogang83
  • guogang83
  • 2013年11月05日 17:34
  • 1130

alter session set cursor_sharing=Exact;

http://www.cnblogs.com/Richardzhu/archive/2013/01/21/2869837.html 一、Cursor_sharing简介:   ...
  • hellojoy
  • hellojoy
  • 2017年02月08日 18:26
  • 513

cursor_sharing的妙用

cursor_sharing的妙用Oracle2009-12-28 10:17:16阅读100评论0  字号:大中小 订阅OLTP系统中,我们总是希望使用绑定变量将sql语句共享在library ca...
  • zero_plus
  • zero_plus
  • 2011年02月24日 23:46
  • 4365

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

声明:本篇实验思路感谢dbsnake老师指点。   在Oracle中,用户应用输入的SQL语句要进行所谓的Parse解析过程,用于生成执行计划,这也就是Query Optimizer的主要工作...
  • xiaoxing1521025
  • xiaoxing1521025
  • 2013年11月28日 15:03
  • 1020
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:关于 cursor_sharing = similar
举报原因:
原因补充:

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