[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                                                                               CON_ID
-------------------------------------------------------------------------------- ----------
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production              0

SCOTT@test01p> alter session set cursor_sharing='similar';
Session altered.

SCOTT@test01p> create table t as select * from dba_objects;
Table created.

SCOTT@test01p> execute dbms_stats.gather_table_stats(user,'t',cascade=>true,method_opt=>'for all columns size 1',no_invalidate=>false);
PL/SQL procedure successfully completed.

SCOTT@test01p> select column_name,histogram from DBA_tab_cols where owner=user and table_name='T' and column_name='OBJECT_ID';
COLUMN_NAME          HISTOGRAM
------------------- ---------------
OBJECT_ID            NONE
--并没有建立直方图在字段OBJECT_ID.

select /*TEST*/ object_name from t where object_id=10;
select /*TEST*/ object_name from t where object_id=11;
select /*TEST*/ object_name from t where object_id=12;

SCOTT@test01p> select sql_text,version_count,address from v$sqlarea where sql_text like 'select /*TEST*/ object_name from t%';
SQL_TEXT                                                      VERSION_COUNT ADDRESS
------------------------------------------------------------- ------------- ----------------
select /*TEST*/ object_name from t where object_id=:"SYS_B_0"             1 000007FF5AFC6B98
--version_count=1

SCOTT@test01p> execute dbms_stats.gather_table_stats(user,'t',cascade=>true,method_opt=>'for all columns size 1 for columns object_id size 254',no_invalidate=>false);
PL/SQL procedure successfully completed.

SCOTT@test01p> select column_name,histogram from DBA_tab_cols where owner=user and table_name='T' and column_name='OBJECT_ID';
COLUMN_NAME          HISTOGRAM
-------------------- ---------------
OBJECT_ID            HYBRID

--HYBRID 第1次看到????

SCOTT@test01p> alter system flush SHARED_POOL;
System altered.

select /*TEST*/ object_name from t where object_id=210;
select /*TEST*/ object_name from t where object_id=211;
select /*TEST*/ object_name from t where object_id=212;

SCOTT@test01p> select sql_text,version_count,address from v$sqlarea where sql_text like 'select /*TEST*/ object_name from t%';
SQL_TEXT                                                      VERSION_COUNT ADDRESS
------------------------------------------------------------- ------------- ----------------
select /*TEST*/ object_name from t where object_id=:"SYS_B_0"             1 000007FF59630E70

-- 12c下cursor_sharing='similar',并没有出现子光标并不奇怪,说不定oracle已经淘汰了cursor_sharing='similar'这种情况,实际上
-- 我猜测使用的是cursor_sharing='force'.

-- 在11g下重复测试:
SCOTT@test> @ver
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

SCOTT@test> alter session set cursor_sharing='similar';
Session altered.

SCOTT@test> create table t as select * from dba_objects;
Table created.

SCOTT@test> execute dbms_stats.gather_table_stats(user,'t',cascade=>true,method_opt=>'for all columns size 1',no_invalidate=>false);
PL/SQL procedure successfully completed.

SCOTT@test> select column_name,histogram from DBA_tab_cols where owner=user and table_name='T' and column_name='OBJECT_ID';
COLUMN_NAME          HISTOGRAM
-------------------- ---------------
OBJECT_ID            NONE

select /*TEST*/ object_name from t where object_id=10;
select /*TEST*/ object_name from t where object_id=11;
select /*TEST*/ object_name from t where object_id=12;

SCOTT@test> select sql_text,version_count,address from v$sqlarea where sql_text like 'select /*TEST*/ object_name from t%';
SQL_TEXT                                                      VERSION_COUNT ADDRESS
------------------------------------------------------------- ------------- ----------------
select /*TEST*/ object_name from t where object_id=:"SYS_B_0"             1 00000000B136C1D0
--version_count=1

SCOTT@test> execute dbms_stats.gather_table_stats(user,'t',cascade=>true,method_opt=>'for all columns size 1 for columns object_id size 254',no_invalidate=>false);
PL/SQL procedure successfully completed.

SCOTT@test> select column_name,histogram from DBA_tab_cols where owner=user and table_name='T' and column_name='OBJECT_ID';
COLUMN_NAME          HISTOGRAM
-------------------- ---------------
OBJECT_ID            HEIGHT BALANCED

--建立了直方图。
select /*TEST*/ object_name from t where object_id=210;
select /*TEST*/ object_name from t where object_id=211;
select /*TEST*/ object_name from t where object_id=212;

SCOTT@test> select sql_text,version_count,address from v$sqlarea where sql_text like 'select /*TEST*/ object_name from t%';
SQL_TEXT                                                      VERSION_COUNT ADDRESS
------------------------------------------------------------- ------------- ----------------
select /*TEST*/ object_name from t where object_id=:"SYS_B_0"             1 00000000B1AA9010

-- 11.2.0.3版本cursor_sharing='similar',并没有出现子光标并不奇怪,说不定oracle已经淘汰了cursor_sharing='similar'这种情况,实际上
-- 我猜测使用的是cursor_sharing='force'.作者出现问题的是11.2.0.1版本。估计oracle已经淘汰cursor_sharing='similar'的情况。

-- 再多做一些测试,在10.2.0.4下重复测试:

10G> @ver
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi

10G> alter session set cursor_sharing='similar';
Session altered.

10G> create table t as select * from dba_objects;
Table created.

10G> execute dbms_stats.gather_table_stats(user,'t',cascade=>true,method_opt=>'for all columns size 1 for columns object_id size 254',no_invalidate=>false);
PL/SQL procedure successfully completed.

10G> select column_name,histogram from DBA_tab_cols where owner=user and table_name='T' and column_name='OBJECT_ID';
COLUMN_NAME          HISTOGRAM
-------------------- ---------------
OBJECT_ID            HEIGHT BALANCED

--建立了直方图。
select /*TEST*/ object_name from t where object_id=210;
select /*TEST*/ object_name from t where object_id=211;
select /*TEST*/ object_name from t where object_id=212;

10G> select sql_id,sql_text,version_count,address from v$sqlarea where sql_text like 'select /*TEST*/ object_name from t%';
SQL_ID        SQL_TEXT                                                      VERSION_COUNT ADDRESS
------------- ------------------------------------------------------------- ------------- ----------------
17a488u6rzrjr select /*TEST*/ object_name from t where object_id=:"SYS_B_0"             3 000000007C993A28
           
--可以发现出现了子光标,version_COUNT=3.如果大量的这些文字变量执行,会产生了大量的子光标。

10G> @share 17a488u6rzrjr
old  15:           and q.sql_id like ''&1''',
new  15:           and q.sql_id like ''17a488u6rzrjr''',
SQL_TEXT                       = select /*TEST*/ object_name from t where object_id=:"SYS_B_0"
SQL_ID                         = 17a488u6rzrjr
ADDRESS                        = 000000007C993A28
CHILD_ADDRESS                  = 00000000772D5918
CHILD_NUMBER                   = 0
--------------------------------------------------
SQL_TEXT                       = select /*TEST*/ object_name from t where object_id=:"SYS_B_0"
SQL_ID                         = 17a488u6rzrjr
ADDRESS                        = 000000007C993A28
CHILD_ADDRESS                  = 0000000077164660
CHILD_NUMBER                   = 1
--------------------------------------------------
SQL_TEXT                       = select /*TEST*/ object_name from t where object_id=:"SYS_B_0"
SQL_ID                         = 17a488u6rzrjr
ADDRESS                        = 000000007C993A28
CHILD_ADDRESS                  = 000000007C8CD510
CHILD_NUMBER                   = 2
--------------------------------------------------
PL/SQL procedure successfully completed.

--奇怪!并没有看见说明不能共享的原因。

--总结:
至少11.2.0.3已经淘汰了cursor_sharing='similar',实际上使用的是force,11G下force+ACS组合很好地解决以前的问题。避免这种情况最佳方法是:
1. 很好合理的使用绑定变量。我一直认为这个是衡量一个项目好坏的一个重要的标准。
2.在需要的字段建立直方图,而不是由oracle的自动统计收集来分析数据,或者修改缺省method_opt参数。

==补充测试:10.2.0.4下:
10G> @ver
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi

10G> execute dbms_stats.gather_table_stats(user,'t',cascade=>true,method_opt=>'for all columns size 1 ',no_invalidate=>false);
PL/SQL procedure successfully completed.

10G> select column_name,histogram from DBA_tab_cols where owner=user and table_name='T' and column_name='OBJECT_ID';
COLUMN_NAME          HISTOGRAM
-------------------- ---------------
OBJECT_ID            NONE

select /*TEST*/ object_name from t where object_id=210;
select /*TEST*/ object_name from t where object_id=211;
select /*TEST*/ object_name from t where object_id=212;

10G> select sql_id,sql_text,version_count,address from v$sqlarea where sql_text like 'select /*TEST*/ object_name from t%';
SQL_ID        SQL_TEXT                                                      VERSION_COUNT ADDRESS
------------- ------------------------------------------------------------  ------------- ----------------
17a488u6rzrjr select /*TEST*/ object_name from t where object_id=:"SYS_B_0"             1 000000007EAF6A60
--可见没有建立直方图没有问题。

时间: 2024-10-23 18:23:19

[20140802]cursor_sharing=similar.txt的相关文章

[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]cost=0.txt

[20140802]cost=0.txt --我记得以前看基于成本优化的书提到,如果计算返回的行0,一般计算选择返回1行,除非查询条件为假. --但是如果计算cost=0会出现什么情况呢? --转载并测试(部分): http://rajeshwaranbtech.blogspot.com/2014/07/cbo-estimates-cost-0.html 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 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%'

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

[20150513]函数索引与CURSOR_SHARING=FORCE

[20150513]函数索引与CURSOR_SHARING=FORCE.txt --经常awr报表,大量听到的建议是你们的应用没有使用绑定变量.国内的许多项目这个问题更加严重,我敢打赌国内80%甚至更高的比例在 --应用中没有绑定变量(OLTP系统). --如果一个新项目我只要看一下程序使用绑定变量的情况,就知道这个项目是垃圾还是豆腐渣工程.到目前为止我接触的项目仅仅有1个做 --的稍微好一点. --如果不修改代码,一个最简单的方式就是修改参数CURSOR_SHARING = FORCE(补充一

由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