触发条件:只需要从索引中就可以取出所需要的结果集,此时就会走索引全扫描

Full Index Scan     按照数据的逻辑顺序读取数据块,会发生单块读事件,
Fast Full Index Scan   按照数据块的物理存储位置顺序读取数据块,会发生多块读事件,理论上索引快速全扫描会比索引全扫描要快

官档的解释:

Full Index Scan

In a full index scan, the database reads the entire index in order. A full index scan is available if a predicate (WHERE clause) in the SQL statement references a column in the index, and in some circumstances when no predicate is specified. A full scan can eliminate sorting because the data is ordered by index key.

原理:ORACLE定位到索引的ROOT BLOCK,然后到BRANCH BLOCK(如果有的话),再定位到第一个LEAF BLOCK, 然后根据LEAF BLOCK的双向链表顺序读取。它所读取的块都是有顺序的,也是经过排序的。

Fast Full Index Scan

A fast full index scan is a full index scan in which the database reads the index blocks in no particular order. The database accesses the data in the index itself, without accessing the table.

Fast full index scans are an alternative to a full table scan when the index contains all the columns that are needed for the query, and at least one column in the index key has the NOT NULLconstraint.

A fast full scan is faster than a normal full index scan because it can use multiblock I/O and can run in parallel just like a table scan.

The database cannot perform fast full index scans of bitmap indexes.

原理:从段头开始,读取包含位图块,ROOT BLOCK,所有的BRANCH BLOCK,LEAF BLOCK,读取的顺序完全有物理存储位置决定,并采取多块读,每次读取DB_FILE_MULTIBLOCK_READ_COUNT个块。查询某个表记录总数的时候,往往基于PRIMARY KEY的INDEX FAST FULL SCAN是最有效的。

测试COST:

SQL> create table t3 as select * from dba_objects;

表已创建。

SQL> create index t3_ix on t3(object_id);

索引已创建。

SQL> alter table t3 modify(object_id not null);

表已更改。

SQL> exec dbms_stats.gather_table_stats('SYS','T3');

PL/SQL 过程已成功完成。

SQL> set autot on
SQL> select count(*)  from t3;

COUNT(*)
----------
     72006

执行计划
----------------------------------------------------------
Plan hash value: 271548554

------------------------------------------------------------------
| Id  | Operation        | Name  | Rows  | Cost (%CPU)| Time     |
------------------------------------------------------------------
|   0 | SELECT STATEMENT |       |     1 |      (0)| 00:00:02 |
|   1 |  SORT AGGREGATE  |       |     1 |            |          |
|   2 |   INDEX FULL SCAN| T3_IX | 63127 |   162   (0)| 00:00:02 |
------------------------------------------------------------------

Note
-----
   - dynamic sampling used for this statement (level=2)

SQL> select count(*)  from t3;

COUNT(*)
----------
     72006

执行计划
----------------------------------------------------------
Plan hash value: 2285970227

-----------------------------------------------------------------------
| Id  | Operation             | Name  | Rows  | Cost (%CPU)| Time     |
-----------------------------------------------------------------------
|   0 | SELECT STATEMENT      |       |     1 |       (0)| 00:00:01 |
|   1 |  SORT AGGREGATE       |       |     1 |            |          |
|   2 |   INDEX FAST FULL SCAN| T3_IX | 63127 |    62   (0)| 00:00:01 |
-----------------------------------------------------------------------

Note
-----
   - dynamic sampling used for this statement (level=2)

可以看到,indexl full scan的cost 为162,index fast full scan 的cost 为62,fast full scan的cost明显要低。

测试SORT:

SQL> select object_id  from t3 where rownum<10 order by object_id;

OBJECT_ID
----------
         2
         3
         4
         5
         6
         7
         8
         9
        10

已选择9行。

执行计划
----------------------------------------------------------
Plan hash value: 633445068

--------------------------------------------------------------------------
| Id  | Operation        | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT |       |     9 |    45 |     2   (0)| 00:00:01 |
|*  1 |  COUNT STOPKEY   |       |       |       |            |          |
|   2 |   INDEX FULL SCAN| T3_IX |     9 |    45 |     2   (0)| 00:00:01 |
--------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

1 - filter(ROWNUM<10)

SQL> select object_id  from t3 where rownum<10 order by object_id;

OBJECT_ID
----------
         2
         3
         4
         5
         6
         7
         8
         9
        10

已选择9行。

执行计划
----------------------------------------------------------
Plan hash value: 512512221

----------------------------------------------------------------------------------------
| Id  | Operation              | Name  | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
----------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT       |       |     9 |    45 |       |   284   (2)| 00:00:04 |
|   1 |  SORT ORDER BY         |       |     9 |    45 |   856K|   284   (2)| 00:00:04 |
|*  2 |   COUNT STOPKEY        |       |       |       |       |            |          |
|   3 |    INDEX FAST FULL SCAN| T3_IX | 72006 |   351K|       |    61   (0)| 00:00:01 |
----------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

2 - filter(ROWNUM<10)

通过执行计划可以看到,fast_full_scan多了一个排序的步骤,而full scan没有这个排序的步骤,说明full scan的数据是根据索引键排好序的,而fast_full_scan的多块读导致其没有按照索引键排好序

index full scan和index fast full scan区别的更多相关文章

  1. Oracle 11G INDEX FULL SCAN 和 INDEX FAST FULL SCAN 对比分析

    SQL> drop table test; 表已删除. SQL> create table test as select * from dba_objects where 1!=1; 表已 ...

  2. 为什么不走INDEX FAST FULL SCAN呢

    INDEX FULL SCAN 索引全扫描.单块读 .它扫描的结果是有序的,因为索引是有序的.它通常发生在 下面几种情况(注意:即使SQL满足以下情况 不一定会走索引全扫描) 1. SQL语句有ord ...

  3. INDEX FAST FULL SCAN和INDEX FULL SCAN

    INDEX FULL SCAN 索引全扫描.单块读 .它扫描的结果是有序的,因为索引是有序的.它通常发生在 下面几种情况(注意:即使SQL满足以下情况 不一定会走索引全扫描) 1. SQL语句有ord ...

  4. Index Full Scan vs Index Fast Full Scan-1103

    [Oracle] Index Full Scan vs Index Fast Full Scan作者:汪海 (Wanghai) 日期:14-Aug-2005 出处:http://spaces.msn. ...

  5. index full scan/index fast full scan/index range scan

    **************************1************************************* 索引状态:          valid.      N/A .    ...

  6. 索引快速扫描(index fast full scan)

    一.索引快速扫描(index fast full scan) 索引快速全扫描(INDEX FAST FULL SCAN)和索引全扫描(INDEX  FULL SCAN)极为类似,它也适用于所有类型的B ...

  7. index range scan,index fast full scan,index skip scan发生的条件

    源链接:https://blog.csdn.net/robinson1988/article/details/4980611 index range scan(索引范围扫描): 1.对于unique ...

  8. index unique scan 与index range scan等的区别

    存取Oracle当中扫描数据的方法(一) Oracle 是一个面向Internet计算环境的数据库.它是在数据库领域一直处于领先地位的甲骨文公司的产品.可以说Oracle关系数据库系统是目前世界上流行 ...

  9. Full scan vs index 执行计划的实验

    根据Oracle-L邮件列表里主题「 Full scan vs index 」的讨论而来. 1.测试环境创建 SYS@HEMESRHTDB2(1.206)> select * from v$ve ...

随机推荐

  1. VS2013 连接 MySQL

    1.安装必须的工具: mysql-connector-net-6.8.3 mysql-installer-community-5.6.16.0.msi mysql-for-visualstudio-1 ...

  2. 011杰信-创建购销合同Excel报表系列-4-建立合同货物(修改,删除):合同货物表是购销合同表的子表

    前面的一篇文章做的是修改删除,这篇文章做的是合同货物的修改和删除. 业务功能如下:

  3. unity发射弓箭轨迹的实现

    无论是愤怒的小鸟,还是弓箭发射功能,亦或者模拟炮弹受重力影响等抛物线轨迹,都可以使用本文的方法,模拟绝对真实. 和往常一样,先说原理.就是抛物运动,在垂直方向上做加速度运动,在水平方向上,做匀速运动. ...

  4. 系统管理模块_岗位管理_改进_使用ModelDroven方案_套用美工写好的页面效果_添加功能与修改功能使用同一个页面

    改进_使用ModelDroven方案 @Controller @Scope("prototype") public class RoleAction extends ActionS ...

  5. java动态代理中的invoke方法是如何被自动调用的(转)

    一.动态代理与静态代理的区别. (1)Proxy类的代码被固定下来,不会因为业务的逐渐庞大而庞大: (2)可以实现AOP编程,这是静态代理无法实现的: (3)解耦,如果用在web业务下,可以实现数据层 ...

  6. VS2013新特性

    大家可能看到我这边颜色和字体和原本不同,这里特意分享给大家背景护眼色值(这对每天看电脑的程序员很重要对不对!)还有字体: 工具-选项-字体和颜色:在项背景点击自定义-色调85 饱和度123 亮度205 ...

  7. Docker的基本使用(部署python项目)

    今天开始利用docker来部署项目,当然,首先,需要安装好Docker,这个在我的上篇中写了 一.准备项目 我写的是一个爬取某ppt网站的代码,就一个ppt1.py是爬虫,然后,ppts是存放下载的p ...

  8. IE浏览器存在的setAttribute bug

    IE的setAttribute中与标准浏览器的有许多不同,主要表现在IE对setAttribute的功能上有些限制,就是不能用setAttribute来设定class.style于onclick等事件 ...

  9. OpenGL编程指南第九章:纹理映射

    转自://http://blog.csdn.net/longhuihu/article/details/8477614 纹理(texture)是一块矩形数据序列,存储的数据为颜色.亮度.alpha值. ...

  10. Python全栈day21-22-23(模块)

    一,python的模块 Python 模块(Module),是一个 Python 文件,以 .py 结尾,包含了 Python 对象定义和Python语句. 模块让你能够有逻辑地组织你的 Python ...