关于cursor_sharing=similar

关于cursor_sharing=similar

2009-02-12 09:41

biti_rainy
关于cursor_sharing=similar

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

SQL>[color=red] alter session set cursor_sharing = similar; [/color]

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
[color=red]parse count (hard)                                                     1619 (硬分析次数)[/color]
parse count (failures)                                                   80

SQL>[color=red] select count(*) from t where object_id = 1000; [/color]

   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
[color=red]parse count (hard)                                                     1620 [/color]
parse count (failures)                                                   80

SQL> [color=red]select count(*) from t where object_id = 1000; [/color]

   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
[color=red]parse count (hard)                                                     1620 [/color]
parse count (failures)                                                   80

SQL> [color=red]select count(*) from t where object_id = 1001; [/color]

   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
[color=red]parse count (hard)                                                     1620(即使object_id发生变化依然没有硬解析)[/color]
parse count (failures)                                                   80

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

SQL>[color=red] analyze table t1 compute statistics for table for columns object_id; [/color]

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
[color=red]parse count (hard)                                                     1640 [/color]
parse count (failures)                                                   80

SQL>[color=red] select count(*) from t1 where object_id = 5000; [/color]

   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
[color=red]parse count (hard)                                                     1641 [/color]
parse count (failures)                                                   80

SQL>[color=red] select count(*) from t1 where object_id = 5000; [/color]

   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
[color=red]parse count (hard)                                                     1641 (重复执行没发生变化)[/color]
parse count (failures)                                                   80

SQL>[color=red] select count(*) from t1 where object_id = 5001; [/color]

   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
[color=red]parse count (hard)                                                     1642 (当object_id变化的时候产生硬分析)[/color]
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则综合了两者的优点。

原文参考
[url]http://blog.csdn.net/biti_rainy/archive/2004/07/12/learn_oracle_20040712_3.aspx[/url]
更多内容参考
[url]http://blog.csdn.net/biti_rainy[/url]

时间: 2024-07-30 10:53:16

关于cursor_sharing=similar的相关文章

[20120421] cursor_sharing=similar和子光标问题.txt

[20120421] cursor_sharing=similar和子光标问题.txt 如果设置cursor_sharing=similar如果存在直方图会产生大量子光标,11GR2的新特性ACS可以很好的解决问题.自己做一些测试说明cursor_sharing=similar产生大量子光标的问题. SQL> select * from v$version; BANNER --------------------------------------------------------------

[20140802]cursor_sharing=similar.txt

[20140802]cursor_sharing=similar.txt --晚上看了http://www.dbaxiaoyu.com/archives/2248,在 cursor_sharing='similar'的情况下,会出现N多子光标(如果查询字段有直方 --图的情况下).实际上oracle在以后的版本会淘汰调cursor_sharing=similar的情况. SCOTT@test01p> @ver BANNER                                     

ANNOUNCEMENT: Deprecating the cursor_sharing = ‘SIMILAR’

ANNOUNCEMENT: Deprecating the cursor_sharing = 'SIMILAR' setting [ID 1169017.1] Applies to:Oracle Server - Enterprise Edition - Version: 11.1.0.6 to 11.2.0.2 - Release: 11.1 to 11.2Information in this document applies to any platform. What is being a

cursor_sharing设置为similar 的弊端

将cursor_sharing设置为similar会产生许多问题:1.对于语句中包含的范围查询(如between, <, !=)或者所捆绑的列中进行直方图统计不适合使用:2.影响11g Adaptive Cursor sharing特性和CBO优化器3.Similar可能产生的一个父游标, 多个子游标,其性能比多个父游标情况更加糟糕(EXACT或 FORCE); 对于第一个,我们做实验如下: 1 修改参数,建表,统计信息 yang@rac1>alter session set cursor_s

由cursor_sharing=force导致的ora-600错误

1.在alert_lxdb.log日志中报600错误 Errors in file /u01/app/oracle/admin/lxdb/udump/lxdb_ora_50379.trc: ORA-00600: internal error code, arguments: [kkslhsh1], [101], [], [], [], [], [], [] 注意这个问题可能会导致产生非常大的trc 文件而导致 文件系统满! 2.本问题的产生根本原因: 设置了 cursor_sharing = f

Oracle: 变量绑定

Parent-Child cursor (父子游标) 父游标:只要SQL语句文本相同,它们就对应 同一个parent cursor. 子游标:在某些情况下,虽然SQL语句的文本相同,但是因为其它 因素不同(这些因素可以在视图V$SQL_SHARED_CURSOR中查看),导致产生不同的child cursor.(重新生成child cursor,也就意味着一次硬解析) cursor_sharing 对 于是否使用绑定变量这个问题,最好是交给应用程序决定,在数据库层面是很难正确判断. (这也是为什

11.2.0.3 Patch Set - Availability and Known Issues [ID 1348336.1]

11.2.0.3 Patch Set - Availability and Known Issues [ID 1348336.1] To Bottom Modified:16-Jan-2013Type:READMEStatus:PUBLISHEDPriority:3 Comments (0) Known Issues specific to the 11.2.0.3 Patch Set Please note that 11.2 Patch Sets 11.2.0.2 and higher ar

《Oracle高性能自动化运维》一一2.3 Library Cache

2.3 Library Cache2.3.1 Library Cache与SQL游标 Library Cache主要用于存放SQL游标,而SQL游标最大化共享是Library Cache优化的重要途径,可以使SQL运行开销最低.性能最优. 1. SQL语句与父游标及子游标 在PL/SQL中,游标(Cursor)是数据集遍历的内存集合.而从广义上讲,游标是SQL语句在Library Cache中的内存载体.SQL语句与游标关系如下: 1)一条SQL语句包含一个父游标(Parent Cursor)和

sga内各组件的简介

系统全局区SGA:  SGA包含的组件:共享池(shared pool):数据库缓冲区高速缓存(database buffer cache):日志缓冲区(redo buffer cache):大池:Java池:流池等. SGA相关视图:   v$sga:              V$SGA这个视图包括了SGA的的总体情况,只包含两个字段:name(SGA内存区名字)和value(内存区的值,单位为字节).它的结果和show sga的结果一致.   v$sgastat:     10g之前用于查