关于cursor_sharing=similar

本文涉及的产品
公共DNS(含HTTPDNS解析),每月1000万次HTTP解析
云解析 DNS,旗舰版 1个月
全局流量管理 GTM,标准版 1个月
简介: 关于cursor_sharing=similar 2009-02-12 09:41 biti_rainy关于cursor_sharing=similar 我们先看看在表没有分析无统计数据情况下的表现 SQL>[color=red] alter ...
关于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]

相关文章
|
机器学习/深度学习 PyTorch 算法框架/工具
【完美解决】RuntimeError: one of the variables needed for gradient computation has been modified by an inp
将loss.backward()函数内的参数retain_graph值设置为True, loss.backward(retain_graph=True),如果retain_graph设置为False,计算过程中的中间变量使用完即被释放掉。
1664 0
|
存储
1032. Sharing (25)
#include using namespace std; /* 题目大意:求两个链表的首个共同结点的地址。如果没有,就输出-1 分析: 用结构体数组存储,node[i]表示地址为i的结点 key表示值,next为...
889 0
|
SQL 关系型数据库 Oracle
[20160517]11GR2Cursor_Sharing=force的bug
[20160517]11GR2Cursor_Sharing=force的bug.txt --链接https://jonathanlewis.wordpress.com/2016/05/16/cursor_sharing-problem/,重复测试: 1.
943 0
|
SQL Oracle 关系型数据库
[20150705]使用CURSOR_SHARING_EXACT提示
[20150705]使用CURSOR_SHARING_EXACT提示.txt --生产系统有一条sql语句遇到性能问题,由于生产系统语句非常复杂,我拿测试用户scott的表作为例子来说明: 1.
998 0