基数反馈(Cardinality Feedback)

基数反馈(Cardinality Feedback)



Cardinality Feedback

Cardinality Feedback基数反馈是版本11.2(11.2.0.1及以后)中引入的关于SQL 性能优化的新特性,该特性主要针对 统计信息陈旧、无直方图或虽然有直方图但仍基数计算不准确的情况,Cardinality基数的计算直接影响到后续的JOIN COST等重要的成本计算评估,造成CBO选择不当的执行计划。以上是Cardinality Feedback特性引入的初衷。

发生情景:

在普通用户下,在sys用户下是会发生feedback特性 
1,没有收集表的统计信息,并且dynamic samping也没有开启 
2,查询条件复杂(比如条件有函数)或者涉及多列,但是没有收集扩展统计信息(extend statics)

运行方式:

  1. 针对上述情况,Oracle会监控操作的实际行数(A-Row),然后对比CBO估算的行数(E-Row)。
  2. 如果两个值相差很大,就记录实际行数(A-Row),做上标记。下次执行时再次进行硬解析,根据实际行数来重新生成执行计划。
  3. 如果两个值相差不大,CBO就不再监控这条SQL语句。

使用的标志;

统计信息中有:

Note

  • cardinality feedback used for this statement

禁用feedback的方式:

hint : opt_param(‘_optimizer_use_feedback’ ‘false’) 
修改参数: alter system set “_optimizer_use_feedback”=false scope=both;

hint:cardinality(test, 1)强制使用

查看share pool中还有那些sql用到了feedback

select sql_ID,USE_FEEDBACK_STATS FROM V$SQL_SHARED_CURSOR where USE_FEEDBACK_STATS =’Y’;


CF特性的功能是非常不错的,oracle在使用了cf反馈评估后更准确的统计数据后会根据此数据生成对于的plan,在再次的执行中还会持续评估统计信息是否准确,以此重复解析,参考如下:

When a cursor is found to be a candidate for Statistics Feedback it will be hard parsed again using the new estimates. The child cursor will be marked as not being shareable and USE_FEEDBACK_STATS set to ‘Y’ in V$SQL_SHARED_CURSOR.
Note: As the need for Statistics Feedback was only detected while execution of this cursor, Statistics Feedback will not actually be used for this child. However it will be used for all further child cursors created.

At the next execution, as a result of the cursor being marked as not shareable, a hard parse will again be performed and a new child created with the optimizer having used the new estimates for creating an optimizer plan.

但是由于cf的评估结果数据只存在内存中(重启之后就需要重新来过),在session之间是不可共用的,并且由于在11g中存在了过多的bug,常见的问题就是在第二次执行sql时候性能下降较多.因此我在11g的数据库中往往会对11.2.0.4以下的数据库会将该特性关闭.

部分bug list

feedback bug








 

 

 

 

 

  

  

 

 

 

 

 

 

 

 

 

>

          

 

>

 

>

 

>

 

>

 

 

 

 

>

     

     

     

     

     

     

     

     

    

    

    

    

        

    

    

 

                                       

                           

 

 

 

 

 

>

 

 

>

 

 

                                    

                                           

                               

                                   

   

   

 

 

>

 

            

 

 

 

 

 

 

 

>

 

>

 

 

>>>

 

 

 

 

>

 

 

 

 

>

 

                               

      

                                          

 

                              

 

                                 

 

   

 

 

>

 

                               

      

                                          

 

                              

 

                                 

 

   

 

 

 

 

>

        

             

 

 

 

>>>>

 

  

                               

                                                

                               

                                  

 

  

      

      

      

      

      

      

      

      

      

  

   

 

 

>>>>

 

  

                               

                                                

                               

                                   

 

  

      

      

      

      

      

      

      

      

      

  

   

 

   

 

 

 

 

 

 

 

 

>

 

>

 

 

>

 

 

 

 

>

 

 

 

 

>

 

        

             

 

>>>>

 

  

                               

                                               

                              

                                 

  

      

      

      

      

      

      

      

      

      

      

  

   

 

 

 

 

 




 
 
 
 
 
 
 
 





 

&

 





 

 

 

 

   


 

>


 

 


 

 

 
  








    

img_e3029f287d989cd04bd75432ecc1c172.png
DBA笔试面试讲解
欢迎与我联系

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值