sql执行计划追踪实验记录

实验分以下几种情况:
1,cursor_sharing为exact,实验字段上无直方图;
2,cursor_sharing为exact,实验字段上有直方图;
3,cursor_sharing为force,实验字段上无直方图;
4,cursor_sharing为force,实验字段上有直方图;
5,cursor_sharing为similar,实验字段上无直方图;
6,cursor_sharing为similar,实验字段上有直方图;
实验以上六种情况下,追踪会话得到的执行计划与直接运行语句得到的执行计划是否一致,六种情况保证不会相互影响。
实验环境:oracle版本:9.2.0.4
                    表空间为本地管理表空间,段自动管理
实验过程记录:
第一种情况:
SQL> select b,count(*) from tab group by b;

         B   COUNT(*)                                                           
---------- ----------                                                           
         1          1                                                           
         2          1                                                           
         3          1                                                           
         4          1                                                           
         5       9991                                                           
      9996          1                                                           
      9997          1                                                           
      9998          1                                                           
      9999          1                                                           
     10000          1                                                           

已选择10行。

SQL> Analyze table tab compute statistics for table for columns b size 1;

表已分析。

SQL> set timing on;
SQL> set autotrace on;
SQL> select * from tab where b='5';
已选择9991行。

已用时间:  00: 00: 03.02

Execution Plan
----------------------------------------------------------                      
   0      SELECT STATEMENT ptimizer=CHOOSE (Cost=4 Card=1000 Bytes=60          
          00)                                                                   
                                                                                
   1    0   TABLE ACCESS (BY INDEX ROWID) OF 'TAB' (Cost=4 Card=1000 B          
          ytes=6000)                                                            
                                                                                
   2    1     INDEX (RANGE SCAN) OF 'IX_TAB_B' (NON-UNIQUE) (Cost=2 Ca          
          rd=1000)                                                              
                                                                                




Statistics
----------------------------------------------------------                      
         23  recursive calls                                                    
          0  db block gets                                                      
       1374  consistent gets                                                    
         21  physical reads                                                     
          0  redo size                                                          
     170751  bytes sent via SQL*Net to client                                   
       7829  bytes received via SQL*Net from client                             
        668  SQL*Net roundtrips to/from client                                  
          0  sorts (memory)                                                     
          0  sorts (disk)                                                       
       9991  rows processed                                                     

SQL> select * from tab where b='3';

         A          B                                                           
---------- ----------                                                           
         3          3                                                           

已用时间:  00: 00: 00.00

Execution Plan
----------------------------------------------------------                      
   0      SELECT STATEMENT ptimizer=CHOOSE (Cost=4 Card=1000 Bytes=60          
          00)                                                                   
                                                                                
   1    0   TABLE ACCESS (BY INDEX ROWID) OF 'TAB' (Cost=4 Card=1000 B          
          ytes=6000)                                                            
                                                                                
   2    1     INDEX (RANGE SCAN) OF 'IX_TAB_B' (NON-UNIQUE) (Cost=2 Ca          
          rd=1000)                                                              
                                                                                




Statistics
----------------------------------------------------------                      
          0  recursive calls                                                    
          0  db block gets                                                      
          4  consistent gets                                                    
          0  physical reads                                                     
          0  redo size                                                          
        421  bytes sent via SQL*Net to client                                   
        503  bytes received via SQL*Net from client                             
          2  SQL*Net roundtrips to/from client                                  
          0  sorts (memory)                                                     
          0  sorts (disk)                                                       
          1  rows processed  
 -----------------------------------------------------------------------------------------------------------
********************************************************************************

select * 
from
 tab where b='5'


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.13          0          0          0           0
Execute      1      0.00       0.00          0          0          0           0
Fetch      668      0.00       0.18         39       1371          0        9991
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total      670      0.00       0.32         39       1371          0        9991

Misses in library cache during parse: 1
Optimizer goal: CHOOSE
Parsing user id: 61  (SLECC_ZFT)

Rows     Row Source Operation
-------  ---------------------------------------------------
   9991  TABLE ACCESS BY INDEX ROWID TAB 
   9991   INDEX RANGE SCAN IX_TAB_B (object id 29809)


Rows     Execution Plan
-------  ---------------------------------------------------
      0  SELECT STATEMENT   GOAL: CHOOSE
   9991   TABLE ACCESS   GOAL: ANALYZED (BY INDEX ROWID) OF 'TAB'
   9991    INDEX   GOAL: ANALYZED (RANGE SCAN) OF 'IX_TAB_B' (NON-UNIQUE)


********************************************************************************

select * 
from
 tab where b='3'


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          0          0           0
Execute      1      0.00       0.00          0          0          0           0
Fetch        2      0.00       0.00          0          4          0           1
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        4      0.00       0.00          0          4          0           1

Misses in library cache during parse: 1
Optimizer goal: CHOOSE
Parsing user id: 61  (SLECC_ZFT)

Rows     Row Source Operation
-------  ---------------------------------------------------
      1  TABLE ACCESS BY INDEX ROWID TAB 
      1   INDEX RANGE SCAN IX_TAB_B (object id 29809)


Rows     Execution Plan
-------  ---------------------------------------------------
      0  SELECT STATEMENT   GOAL: CHOOSE
      1   TABLE ACCESS   GOAL: ANALYZED (BY INDEX ROWID) OF 'TAB'
      1    INDEX   GOAL: ANALYZED (RANGE SCAN) OF 'IX_TAB_B' (NON-UNIQUE)


********************************************************************************
第二种情况:
SQL> Analyze table tab compute statistics for table for columns b size 10;

表已分析。

SQL> set timing on;
SQL> set autotrace on;
SQL> select * from tab where b='5';
已选择9991行。

已用时间:  00: 00: 02.09

Execution Plan
----------------------------------------------------------                      
   0      SELECT STATEMENT ptimizer=CHOOSE (Cost=4 Card=9991 Bytes=59          
          946)                                                                  
                                                                                
   1    0   TABLE ACCESS (FULL) OF 'TAB' (Cost=4 Card=9991 Bytes=59946          
          )                                                                     
                                                                                




Statistics
----------------------------------------------------------                      
         52  recursive calls                                                    
          0  db block gets                                                      
        694  consistent gets                                                    
          0  physical reads                                                     
          0  redo size                                                          
     170751  bytes sent via SQL*Net to client                                   
       7829  bytes received via SQL*Net from client                             
        668  SQL*Net roundtrips to/from client                                  
          0  sorts (memory)                                                     
          0  sorts (disk)                                                       
       9991  rows processed                                                     

SQL> select * from tab where b='3';

         A          B                                                           
---------- ----------                                                           
         3          3                                                           

已用时间:  00: 00: 00.00

Execution Plan
----------------------------------------------------------                      
   0      SELECT STATEMENT ptimizer=CHOOSE (Cost=2 Card=1 Bytes=6)             
   1    0   TABLE ACCESS (BY INDEX ROWID) OF 'TAB' (Cost=2 Card=1 Byte          
          s=6)                                                                  
                                                                                
   2    1     INDEX (RANGE SCAN) OF 'IX_TAB_B' (NON-UNIQUE) (Cost=1 Ca          
          rd=1)                                                                 
                                                                                




Statistics
----------------------------------------------------------                      
          0  recursive calls                                                    
          0  db block gets                                                      
          4  consistent gets                                                    
          2  physical reads                                                     
          0  redo size                                                          
        421  bytes sent via SQL*Net to client                                   
        503  bytes received via SQL*Net from client                             
          2  SQL*Net roundtrips to/from client                                  
          0  sorts (memory)                                                     
          0  sorts (disk)                                                       
          1  rows processed   
---------------------------------------------------------------------------------------------------
********************************************************************************

select * 
from
 tab where b='5'


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.01       0.16          0          0          0           0
Execute      1      0.00       0.00          0          0          0           0
Fetch      668      0.00       0.05         21        688          0        9991
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total      670      0.01       0.21         21        688          0        9991

Misses in library cache during parse: 1
Optimizer goal: CHOOSE
Parsing user id: 61  (SLECC_ZFT)

Rows     Row Source Operation
-------  ---------------------------------------------------
   9991  TABLE ACCESS FULL TAB 


Rows     Execution Plan
-------  ---------------------------------------------------
      0  SELECT STATEMENT   GOAL: CHOOSE
   9991   TABLE ACCESS   GOAL: ANALYZED (FULL) OF 'TAB'

********************************************************************************

select * 
from
 tab where b='3'


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          0          0           0
Execute      1      0.00       0.00          0          0          0           0
Fetch        2      0.00       0.01          2          4          0           1
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        4      0.00       0.01          2          4          0           1

Misses in library cache during parse: 1
Optimizer goal: CHOOSE
Parsing user id: 61  (SLECC_ZFT)

Rows     Row Source Operation
-------  ---------------------------------------------------
      1  TABLE ACCESS BY INDEX ROWID TAB 
      1   INDEX RANGE SCAN IX_TAB_B (object id 29809)


Rows     Execution Plan
-------  ---------------------------------------------------
      0  SELECT STATEMENT   GOAL: CHOOSE
      1   TABLE ACCESS   GOAL: ANALYZED (BY INDEX ROWID) OF 'TAB'
      1    INDEX   GOAL: ANALYZED (RANGE SCAN) OF 'IX_TAB_B' (NON-UNIQUE)


********************************************************************************
以上两种情况下,cursor_sharing为exact,两种方式下得到的执行计划一致:在字段数据分布不均匀的情况下,有直方图可得到预期的执行计划;无直方图,oracle无法判断数据分布情况,无论检索何值都走了索引。
--------------------------------------------------------------------------------------------------------------
 第三种情况:
 SQL> Analyze table tab compute statistics for table for columns b size 1;

表已分析。

SQL> set timing on;
SQL> set autotrace on;
SQL> select * from tab where b='5';
已选择9991行。

已用时间:  00: 00: 03.00

Execution Plan
----------------------------------------------------------                      
   0      SELECT STATEMENT ptimizer=CHOOSE (Cost=4 Card=1000 Bytes=60          
          00)                                                                   
                                                                                
   1    0   TABLE ACCESS (BY INDEX ROWID) OF 'TAB' (Cost=4 Card=1000 B          
          ytes=6000)                                                            
                                                                                
   2    1     INDEX (RANGE SCAN) OF 'IX_TAB_B' (NON-UNIQUE) (Cost=2 Ca          
          rd=1000)                                                              
                                                                                




Statistics
----------------------------------------------------------                      
         52  recursive calls                                                    
          0  db block gets                                                      
       1377  consistent gets                                                    
         21  physical reads                                                     
          0  redo size                                                          
     170751  bytes sent via SQL*Net to client                                   
       7829  bytes received via SQL*Net from client                             
        668  SQL*Net roundtrips to/from client                                  
          0  sorts (memory)                                                     
          0  sorts (disk)                                                       
       9991  rows processed                                                     

SQL> select * from tab where b='3';

         A          B                                                           
---------- ----------                                                           
         3          3                                                           

已用时间:  00: 00: 00.00

Execution Plan
----------------------------------------------------------                      
   0      SELECT STATEMENT ptimizer=CHOOSE (Cost=4 Card=1000 Bytes=60          
          00)                                                                   
                                                                                
   1    0   TABLE ACCESS (BY INDEX ROWID) OF 'TAB' (Cost=4 Card=1000 B          
          ytes=6000)                                                            
                                                                                
   2    1     INDEX (RANGE SCAN) OF 'IX_TAB_B' (NON-UNIQUE) (Cost=2 Ca          
          rd=1000)                                                              
                                                                                




Statistics
----------------------------------------------------------                      
          0  recursive calls                                                    
          0  db block gets                                                      
          4  consistent gets                                                    
          0  physical reads                                                     
          0  redo size                                                          
        421  bytes sent via SQL*Net to client                                   
        503  bytes received via SQL*Net from client                             
          2  SQL*Net roundtrips to/from client                                  
          0  sorts (memory)                                                     
          0  sorts (disk)                                                       
          1  rows processed
---------------------------------------------------------------------------------------------------------
********************************************************************************

select * 
from
 tab where b=:"SYS_B_0"


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        2      0.03       0.12          0          0          0           0
Execute      2      0.00       0.00          0          0          0           0
Fetch      670      0.00       0.14         39       1375          0        9992
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total      674      0.03       0.26         39       1375          0        9992

Misses in library cache during parse: 1
Optimizer goal: CHOOSE
Parsing user id: 61  (SLECC_ZFT)

Rows     Row Source Operation
-------  ---------------------------------------------------
   9991  TABLE ACCESS BY INDEX ROWID TAB 
   9991   INDEX RANGE SCAN IX_TAB_B (object id 29809)


Rows     Execution Plan
-------  ---------------------------------------------------
      0  SELECT STATEMENT   GOAL: CHOOSE
   9991   TABLE ACCESS   GOAL: ANALYZED (BY INDEX ROWID) OF 'TAB'
   9991    INDEX   GOAL: ANALYZED (RANGE SCAN) OF 'IX_TAB_B' (NON-UNIQUE)


********************************************************************************

   第三种情况下,两种方式得到的执行计划也一致。
------------------------------------------------------------------------------------------------------------
    第四种情况:
SQL> Analyze table tab compute statistics for table for columns b size 10;

表已分析。

SQL> set timing on;
SQL> set autotrace on;
SQL> select * from tab where b='5';
已选择9991行。

已用时间:  00: 00: 03.01

Execution Plan
----------------------------------------------------------                      
   0      SELECT STATEMENT ptimizer=CHOOSE (Cost=4 Card=9991 Bytes=59          
          946)                                                                  
                                                                                
   1    0   TABLE ACCESS (FULL) OF 'TAB' (Cost=4 Card=9991 Bytes=59946          
          )                                                                     
                                                                                




Statistics
----------------------------------------------------------                      
         52  recursive calls                                                    
          0  db block gets                                                      
       1377  consistent gets                                                    
         21  physical reads                                                     
          0  redo size                                                          
     170751  bytes sent via SQL*Net to client                                   
       7829  bytes received via SQL*Net from client                             
        668  SQL*Net roundtrips to/from client                                  
          0  sorts (memory)                                                     
          0  sorts (disk)                                                       
       9991  rows processed                                                     

SQL> select * from tab where b='3';

         A          B                                                           
---------- ----------                                                           
         3          3                                                           

已用时间:  00: 00: 00.00

Execution Plan
----------------------------------------------------------                      
   0      SELECT STATEMENT ptimizer=CHOOSE (Cost=2 Card=1 Bytes=6)             
   1    0   TABLE ACCESS (BY INDEX ROWID) OF 'TAB' (Cost=2 Card=1 Byte          
          s=6)                                                                  
                                                                                
   2    1     INDEX (RANGE SCAN) OF 'IX_TAB_B' (NON-UNIQUE) (Cost=1 Ca          
          rd=1)                                                                 
                                                                                




Statistics
----------------------------------------------------------                      
          0  recursive calls                                                    
          0  db block gets                                                      
          4  consistent gets                                                    
          0  physical reads                                                     
          0  redo size                                                          
        421  bytes sent via SQL*Net to client                                   
        503  bytes received via SQL*Net from client                             
          2  SQL*Net roundtrips to/from client                                  
          0  sorts (memory)                                                     
          0  sorts (disk)                                                       
          1  rows processed
SQL> alter system flush shared_pool;

系统已更改。

已用时间:  00: 00: 00.00
SQL> select * from tab where b='3';

         A          B                                                           
---------- ----------                                                           
         3          3                                                           

已用时间:  00: 00: 00.00

Execution Plan
----------------------------------------------------------                      
   0      SELECT STATEMENT ptimizer=CHOOSE (Cost=2 Card=1 Bytes=6)             
   1    0   TABLE ACCESS (BY INDEX ROWID) OF 'TAB' (Cost=2 Card=1 Byte          
          s=6)                                                                  
                                                                                
   2    1     INDEX (RANGE SCAN) OF 'IX_TAB_B' (NON-UNIQUE) (Cost=1 Ca          
          rd=1)                                                                 
                                                                                




Statistics
----------------------------------------------------------                      
        308  recursive calls                                                    
          0  db block gets                                                      
         47  consistent gets                                                    
          0  physical reads                                                     
          0  redo size                                                          
        421  bytes sent via SQL*Net to client                                   
        503  bytes received via SQL*Net from client                             
          2  SQL*Net roundtrips to/from client                                  
          7  sorts (memory)                                                     
          0  sorts (disk)                                                       
          1  rows processed                                                     

SQL> select * from tab where b='5';
已选择9991行。

已用时间:  00: 00: 03.01

Execution Plan
----------------------------------------------------------                      
   0      SELECT STATEMENT ptimizer=CHOOSE (Cost=4 Card=9991 Bytes=59          
          946)                                                                  
                                                                                
   1    0   TABLE ACCESS (FULL) OF 'TAB' (Cost=4 Card=9991 Bytes=59946          
          )                                                                     
                                                                                




Statistics
----------------------------------------------------------                      
          0  recursive calls                                                    
          0  db block gets                                                      
       1371  consistent gets                                                    
          0  physical reads                                                     
          0  redo size                                                          
     170751  bytes sent via SQL*Net to client                                   
       7829  bytes received via SQL*Net from client                             
        668  SQL*Net roundtrips to/from client                                  
          0  sorts (memory)                                                     
          0  sorts (disk)                                                       
       9991  rows processed
这种方式下,无论先执行哪条语句,都能得到预期的执行计划;
-------------------------------------------------------------------------------------------------------------
********************************************************************************

select * 
from
 tab where b=:"SYS_B_0"


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        4      0.00       0.10          0         83          0           0
Execute      4      0.00       0.00          0          0          0           0
Fetch     1340      0.00       0.13         39       2750          0       19984
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total     1348      0.00       0.24         39       2833          0       19984

Misses in library cache during parse: 2
Optimizer goal: CHOOSE
Parsing user id: 61  (SLECC_ZFT)

Rows     Row Source Operation
-------  ---------------------------------------------------
   9991  TABLE ACCESS BY INDEX ROWID TAB 
   9991   INDEX RANGE SCAN IX_TAB_B (object id 29809)


Rows     Execution Plan
-------  ---------------------------------------------------
      0  SELECT STATEMENT   GOAL: CHOOSE
   9991   TABLE ACCESS   GOAL: ANALYZED (BY INDEX ROWID) OF 'TAB'
   9991    INDEX   GOAL: ANALYZED (RANGE SCAN) OF 'IX_TAB_B' (NON-UNIQUE)


********************************************************************************

alter system flush shared_pool


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          0          0           0
Execute      1      0.00       0.00          0          0          0           0
Fetch        0      0.00       0.00          0          0          0           0
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        2      0.00       0.00          0          0          0           0

Misses in library cache during parse: 1
Optimizer goal: CHOOSE
Parsing user id: 61  (SLECC_ZFT)
这种方式下,无论先执行哪条语句,都是一样的
********************************************************************************
综上,第四种情况下,追踪客户会话得到的执行计划与直接运行语句得到的执行计划出现了不一致的现象。直接运行语句得到的执行计划只是理论上的。
从内存中直接查询执行计划,结果显示和跟踪会话得到的执行计划一致,都走索引。

1.SELECT sql_text, address, hash_value FROM v$sql

 WHERE sql_text like '%TAG%';

    2. SELECT operation, options, object_name, cost FROM v$sql_plan

      WHERE address = ADDRESS  AND hash_value = HASHVALUE;
看来,直接运行语句得到的执行计划不一定是真正的执行计划,只是比较理想的执行计划。理论上的。要想获得真正的执行计划,可以追踪客户会话或是直接利用视图查询。
但是,实验结果又与理论不一致。不知道在真正的绑定变量情况下是怎样的。
cursor_sharing为force情况下的实验就到这吧。下面实验similar,自己库中是这种情况,但经常出现7445错误,不知道是不是这个参数的原因。

-------------------------------------------------------------------------------------------------------------
第五种情况:(cursor_sharing为similar,实验字段上无直方图;)
在这种情况下,直接运行语句得到的执行计划是否准确??
SQL> Analyze table tab compute statistics for table for columns b size 1;

表已分析。

SQL> select * from tab where b='5';
已选择9991行。

已用时间:  00: 00: 03.00

Execution Plan
----------------------------------------------------------                      
   0      SELECT STATEMENT ptimizer=CHOOSE (Cost=4 Card=1000 Bytes=60          
          00)                                                                   
                                                                                
   1    0   TABLE ACCESS (BY INDEX ROWID) OF 'TAB' (Cost=4 Card=1000 B          
          ytes=6000)                                                            
                                                                                
   2    1     INDEX (RANGE SCAN) OF 'IX_TAB_B' (NON-UNIQUE) (Cost=2 Ca          
          rd=1000)                                                              
                                                                                




Statistics
----------------------------------------------------------                      
          0  recursive calls                                                    
          0  db block gets                                                      
       1371  consistent gets                                                    
          0  physical reads                                                     
          0  redo size                                                          
     170751  bytes sent via SQL*Net to client                                   
       7829  bytes received via SQL*Net from client                             
        668  SQL*Net roundtrips to/from client                                  
          0  sorts (memory)                                                     
          0  sorts (disk)                                                       
       9991  rows processed                                                     

SQL> select * from tab where b='3';

         A          B                                                           
---------- ----------                                                           
         3          3                                                           

已用时间:  00: 00: 00.00

Execution Plan
----------------------------------------------------------                      
   0      SELECT STATEMENT ptimizer=CHOOSE (Cost=4 Card=1000 Bytes=60          
          00)                                                                   
                                                                                
   1    0   TABLE ACCESS (BY INDEX ROWID) OF 'TAB' (Cost=4 Card=1000 B          
          ytes=6000)                                                            
                                                                                
   2    1     INDEX (RANGE SCAN) OF 'IX_TAB_B' (NON-UNIQUE) (Cost=2 Ca          
          rd=1000)                                                              
                                                                                




Statistics
----------------------------------------------------------                      
          0  recursive calls                                                    
          0  db block gets                                                      
          4  consistent gets                                                    
          0  physical reads                                                     
          0  redo size                                                          
        421  bytes sent via SQL*Net to client                                   
        503  bytes received via SQL*Net from client                             
          2  SQL*Net roundtrips to/from client                                  
          0  sorts (memory)                                                     
          0  sorts (disk)                                                       
          1  rows processed                     
-------------------------------------------------------------------------------------------------------------
    ********************************************************************************

select * 
from
 tab where b=:"SYS_B_0"


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        2      0.04       0.12          0          0          0           0
Execute      2      0.00       0.00          0          0          0           0
Fetch      670      0.00       0.10         39       1375          0        9992
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total      674      0.04       0.23         39       1375          0        9992

Misses in library cache during parse: 1
Optimizer goal: CHOOSE
Parsing user id: 61  (SLECC_ZFT)

Rows     Row Source Operation
-------  ---------------------------------------------------
   9991  TABLE ACCESS BY INDEX ROWID TAB 
   9991   INDEX RANGE SCAN IX_TAB_B (object id 29809)


Rows     Execution Plan
-------  ---------------------------------------------------
      0  SELECT STATEMENT   GOAL: CHOOSE
   9991   TABLE ACCESS   GOAL: ANALYZED (BY INDEX ROWID) OF 'TAB'
   9991    INDEX   GOAL: ANALYZED (RANGE SCAN) OF 'IX_TAB_B' (NON-UNIQUE)


********************************************************************************
第六种情况:(cursor_sharing为similar,实验字段上有直方图;)
利用SQL> Analyze table tab compute statistics for table for columns b size 10;获取直方图,与force一样。
利用SQL> execute dbms_stats.gather_table_stats(ownname=>'SLECC_ZFT',tabname=>'TAB',E
STIMATE_PERCENT=>DBMS_STATS.AUTO_SAMPLE_SIZE,METHOD_OPT=>'FOR ALL COLUMNS SIZE A
UTO',cascade=>TRUE);收集直方图。还是一样。
奇怪了,理论上,有直方图的情况下,similar应该和exact一样,但是,怎么在内存中还是和force一样呢??
这参数,还真是不怎么样。
总结:cursor_sharing为exact,理论与实验结果一致;
无论为similar还是force,无论是否有直方图,实际执行计划与理论都不一致。

只有cursor_sharing为exact的情况下,才能得到预期的执行计划。看来,修改这个参数,还真是得慎重啊。代码烂,不能让oracle来擦屁股。
                    

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/22295535/viewspace-712815/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/22295535/viewspace-712815/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值