当前位置:  数据库>oracle

Oracle 11g R2 INDEX FAST FULL SCAN 成本计算

    来源: 互联网  发布时间:2017-04-05

    本文导语: SQL> select * from v$version where rownum create index i_test_owner on test(owner); Index created. INDEX FAST FULL SCAN只需要扫描叶子块,并且采用多块读,所以查询LEAF_BLOCKS SQL>  select leaf_blocks from user_indexes where index_name='I_TEST_OWNER'; LEAF_BLOCKS-----------   ...

SQL> select * from v$version where rownum create index i_test_owner on test(owner);

Index created.

INDEX FAST FULL SCAN只需要扫描叶子块,并且采用多块读,所以查询LEAF_BLOCKS

SQL>  select leaf_blocks from user_indexes where index_name='I_TEST_OWNER';

LEAF_BLOCKS
-----------
         22

SQL> explain plan for select count(owner) from test;

Explained.

SQL> select cpu_cost from plan_table;

  CPU_COST
----------
   1356672
  
SQL>  select pname, pval1 from sys.aux_stats$ where sname='SYSSTATS_MAIN';



PNAME                               PVAL1
------------------------------ ----------
CPUSPEED                             2500
CPUSPEEDNW                     2696.05568
IOSEEKTIM                              10
IOTFRSPEED                           4096
MAXTHR
MBRC                                   12
MREADTIM                               30
SLAVETHR
SREADTIM                                5









9 rows selected.

因为MBRC不为空,所以CBO会采用工作量模式计算Cost
  
INDEX FAST FULL SCAN 成本计算公式如下:

Cost = (
       #SRds * sreadtim +
       #MRds * mreadtim +
       CPUCycles / cpuspeed /1000
       ) / sreadtime
      
#SRds - number of single block reads
#MRds - number of multi block reads
#CPUCyles - number of CPU cycles







sreadtim - single block read time
mreadtim - multi block read time
cpuspeed - CPU cycles per second

Cost = (
       #SRds * sreadtim +                            ---SRds=0
       #MRds * mreadtim +                          ---MRds=Leaf_Blocks/MBCR=22/12, mreadtim=30
       CPUCycles / cpuspeed / 1000         ---CPUCycles=PLAN_TABLE.CPU_COST,cpuspeed=2500
       ) / sreadtime



所以人工计算的成本等于:
SQL> select ceil(22/12*30/5)+ceil(1356672/2500/5/1000)+1 from dual; ---+1是因为 _table_scan_cost_plus_one设置为true

CEIL(22/12*30/5)+CEIL(1356672/2500/5/1000)+1
--------------------------------------------
                                          13
                                                                                   
SQL> select count(owner) from test;



Execution Plan
----------------------------------------------------------
Plan hash value: 1992658997

--------------------------------------------------------------------------------------
| Id  | Operation             | Name         | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT      |              |     1 |     5 |    13   (0)| 00:00:01 |
|   1 |  SORT AGGREGATE       |              |     1 |     5 |            |          |
|   2 |   INDEX FAST FULL SCAN| I_TEST_OWNER | 10000 | 50000 |    13   (0)| 00:00:01 |
--------------------------------------------------------------------------------------





现在采用非工作量统计来计算Cost

SQL> begin
   dbms_stats.set_system_stats('CPUSPEED',0);
   dbms_stats.set_system_stats('SREADTIM',0);
   dbms_stats.set_system_stats('MREADTIM',0);
   dbms_stats.set_system_stats('MBRC',0);
end;
/
  2    3    4    5    6    7






PL/SQL procedure successfully completed.

SQL> show parameter db_file_multiblock_read_count

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_file_multiblock_read_count        integer     16

SQL> select (select pval1 from sys.aux_stats$ where pname = 'IOSEEKTIM') +
       (select value
          from v$parameter
         where name = 'db_file_multiblock_read_count') *
  2    3    4    5         (select value from v$parameter where name = 'db_block_size') /
  6         (select pval1 from sys.aux_stats$ where pname = 'IOTFRSPEED') "mreadtim"
  7    from dual;





  mreadtim
----------
        42
SQL> select (select pval1 from sys.aux_stats$ where pname = 'IOSEEKTIM') +
       (select value from v$parameter where name = 'db_block_size') /
       (select pval1 from sys.aux_stats$ where pname = 'IOTFRSPEED') "sreadtim"
  from dual;  2    3    4





  sreadtim
----------
        12
       
SQL> select cpu_cost from plan_table;



  CPU_COST
----------
   1356672

根据成本计算公式

Cost = (
       #SRds * sreadtim +                            ---SRds=0
       #MRds * mreadtim +                          ---MRds=Leaf_Blocks/db_file_multiblock_read_count=22/16, mreadtim=42
       CPUCycles / cpuspeed / 1000         ---CPUCycles=PLAN_TABLE.CPU_COST,cpuspeed=2696.05568
       ) / sreadtime
      
那么手工计算的Cost等于:





SQL> select ceil(22/16*42/12)+ceil(1356672/2696.05568/12/1000)+1 from dual;

CEIL(22/16*42/12)+CEIL(1356672/2696.05568/12/1000)+1
----------------------------------------------------
                                                   7
SQL> set autot trace
SQL> select count(owner) from test;



Execution Plan
----------------------------------------------------------
Plan hash value: 1992658997

--------------------------------------------------------------------------------------
| Id  | Operation             | Name         | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT      |              |     1 |     5 |     7   (0)| 00:00:01 |
|   1 |  SORT AGGREGATE       |              |     1 |     5 |            |          |
|   2 |   INDEX FAST FULL SCAN| I_TEST_OWNER | 10000 | 50000 |     7   (0)| 00:00:01 |
--------------------------------------------------------------------------------------





从实验中可以看到,INDEX FAST FULL SCAN 在11gR2中的成本算法依然和9i,10g一样,没有变化。


    
 
 
 
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐
  • Oracle Index 的三个常见问题
  • 用jsp做了一个主页(http://www.oracle-dev.com/wzp/index.jsp)欢迎大家提出建议
  • Oracle Index 的三个问题
  • Oracle 12c发布简单介绍及官方下载地址
  • 在linux下安装oracle,如何设置让oracle自动启动!也就是让oracle那个服务自动启动,不是手动的
  • oracle 11g最新版官方下载地址
  • 请问su oracle 和su - oracle有什么不同?
  • Oracle 数据库(oracle Database)Select 多表关联查询方式
  • 虚拟机装Oracle R12与Oracle10g
  • Oracle数据库(Oracle Database)体系结构及基本组成介绍
  • Oracle 数据库开发工具 Oracle SQL Developer
  • 如何设置让Oracle SQL Developer显示的时间包含时分秒
  • Oracle EBS R12 支持 Oracle Database 11g
  • Oracle 10g和Oracle 11g网格技术介绍
  • SCO unix下安装oracle,但没有光盘,请大家推荐一个oracle下载站点(unix版本的)。谢谢!!!!
  • oracle中如何把表中具有相同值列的多行数据合并成一行
  • 请问大家用oracle数据库, 用import oracle.*;下的东西么? 还是用标准库?
  • Oracle 数据库(oracle Database)性能调优技术详解
  • Linux /$ORACLE_HOME $ORACLE_HOME
  • ORACLE日期相关操作
  • Linux系统下Oracle的启动与Oracle监听的启动
  • ORACLE数据库常用字段数据类型介绍
  • 请问在solaris下安装ORACLE,用root用户和用oracle用户安装有什么区别么?
  • Oracle 12c的九大最新技术特性介绍
  • 网间Oracle的连接,远程连接Oracle服务器??


  • 站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3