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

一、索引快速扫描(index fast full scan)

索引快速全扫描(INDEX FAST FULL SCAN)和索引全扫描(INDEX  FULL SCAN)极为类似,它也适用于所有类型的B树索引(包括唯一性索引和非唯一性索引)。和索引全扫描一样,索引快速全扫描也需要扫描目标索引所有叶子块的所有索引行。

索引快速全扫描与索引全扫描相比有如下三点区别。

(1)索引快速全扫描只适用于CBO。

(2)索引快速全扫描可以使用多块读,也可以并行执行。

(3)索引快速全扫描的执行结果不一定是有序的。这是因为索引快速全扫描时Oracle是根据索引行在磁盘上的物理存储顺序来扫描,而不是根据索引行的逻辑顺序来扫描的,所以扫描结果才不一定有序(对于单个索引叶子块中的索引行而言,其物理存储顺序和逻辑存储顺序一致;但对于物理存储位置相邻的索引叶子块而言,块与块之间索引行的物理存储顺序则不一定在逻辑上有序)。

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 NULL constraint(至少有一个有非空约束). A fast full scan accesses the data in the index itself, without accessing the table. It cannot be used to eliminate a sort operation, because the data is not ordered by the index key. It reads the entire index using multiblock reads, unlike a full index scan, and can be parallelized.

You can specify fast full index scans with the initialization parameter OPTIMIZER_FEATURES_ENABLE or the INDEX_FFS hint. Fast full index scans cannot be performed against bitmap indexes.

A fast full scan is faster than a normal full index scan in that it can use multiblock I/O(一次可以读多个块,跟全表扫描一样) and can be parallelized just like a table scan.

二、例子

1、针对scott的emp表

select empno from emp;

clip_image001

继续插入数据

BEGIN

FOR I IN 0..1000 LOOP

INSERT INTO EMP(EMPNO,ENAME) VALUES(

I,CONCAT('TBL',I));

END LOOP;

END;

对表EMP及主键索引重新收集一下统计信息:

analyze table emp compute statistics for table for all columns for all indexes;

重新执行

select empno from emp;

clip_image002

加载策略变成了Fast Full Index Scans

 

三、对比Index Fast Full Scans与Index Fast Full Scans

INDEX FULL SCAN 与 INDEX FAST FULL SCAN两个长相差不多,乃是一母同胞,因此既有其共性,也有其个性。两者来说其共性是不用扫描
表而是通过索引就可以直接返回所需要的所有数据。这对提高查询性能而言,无疑是一个难得的数据访问方式之一,因为索引中存储的数据通常
是远小于原始表的数据。下面具体来看看两者之间的异同。

我们对比一下 Index Fast Full Scans与Index Fast Full Scans

select /*+ index_ffs(emp pk_emp) */empno from emp;

clip_image003

select /*+ index(emp pk_emp) */empno from emp;

clip_image004

和index full scan不同,index fast full scan的执行结果并没有按照主键索引PK_EMP的索引键值前导列EMPNO来排序,即索引快速全扫描的执行结果确实不一定是有序的。

四、结论

  • 当select和where中出现的列都存在索引是发生index full scan与index fast full scan的前提
  • index fast full scan使用多块读的方式读取索引块,产生db file scattered reads 事件,读取时高效,但为无序读取
  • index full scan使用单块读方式有序读取索引块,产生db file sequential reads事件,当采用该方式读取大量索引全扫描,效率低下

参考

INDEX FULL SCAN vs INDEX FAST FULL SCAN

索引快速全扫描

posted on 2015-04-29 20:57  小强斋太  阅读(24410)  评论(0编辑  收藏  举报

导航