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

1、索引快速掃描(index fast full scan)

索引快速全掃描(INDEX FAST FULL SCAN)和索引全掃描(INDEX  FULL SCAN)極爲相似,它也適用於全部類型的B樹索引(包括惟一性索引和非惟一性索引)。和索引全掃描同樣,索引快速全掃描也須要掃描目標索引全部葉子塊的全部索引行。性能

索引快速全掃描與索引全掃描相比有以下三點區別。spa

(1)索引快速全掃描只適用於CBO。.net

(2)索引快速全掃描可使用多塊讀,也能夠並行執行。code

(3)索引快速全掃描的執行結果不必定是有序的。這是由於索引快速全掃描時Oracle是根據索引行在磁盤上的物理存儲順序來掃描,而不是根據索引行的邏輯順序來掃描的,因此掃描結果纔不必定有序(對於單個索引葉子塊中的索引行而言,其物理存儲順序和邏輯存儲順序一致;但對於物理存儲位置相鄰的索引葉子塊而言,塊與塊之間索引行的物理存儲順序則不必定在邏輯上有序)。orm

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.htm

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.blog

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.排序

2、例子

一、針對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

 

3、對比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來排序,即索引快速全掃描的執行結果確實不必定是有序的。

4、結論

  • 當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

索引快速全掃描

相關文章
相關標籤/搜索