index full scan/index fast full scan/index range scan

**************************1*************************************

索引状态:          valid、      N/A 、      unusable 解释


确认索引状态

--user_indexes 确认该索引状态是 N/A
SQL> select index_name,status from user_indexes where index_name='IND01';

INDEX_NAME                     STATUS
------------------------------ --------
IND01                          N/A

--user_ind_partitions 确认该索引分区的状态是 USABLE
SQL> select partition_name, status from user_ind_partitions where index_name = 'IND01';

PARTITION_NAME                 STATUS
------------------------------ --------
P01                            USABLE
P02                            USABLE

--手动把该索引 状态改为 UNUSABLE
SQL> alter index ind01 unusable;

Index altered.

--再次确认该索引状态是 N/A
SQL> select status from user_indexes where index_name = 'IND01';

STATUS
--------
N/A

--再次确认该索引分区的状态是 UNUSABLE
SQL> select partition_name, status from user_ind_partitions where index_name = 'IND01';

PARTITION_NAME                 STATUS
------------------------------ --------
P01                            UNUSABLE
P02                            UNUSABLE


总结:索引分区的状态修改了,但是该索引的状态依然是 N/A


      
状态:
      valid:当前索引有效
      N/A :分区索引 未知
      unusable:索引失效

 

**************************2*************************************

SQL> create table test (id number not null, name varchar2(30));

表已创建。

SQL> insert into test select rownum, object_name from dba_objects;

已创建30366行。

SQL> commit;

提交完成。

SQL> create index ind_test_id on test(id);

索引已创建。


SQL> exec dbms_stats.gather_table_stats(user, 'test');

PL/SQL 过程已成功完成。

SQL> set autot trace exp
SQL> select * from test where id < 10;

Execution Plan
----------------------------------------------------------
   0      SELECT STATEMENT Optimizer=CHOOSE (Cost=3 Card=9 Bytes=252)
   1    0   TABLE ACCESS (BY INDEX ROWID) OF 'TEST' (Cost=3 Card=9 Bytes=252)
   2    1     INDEX (RANGE SCAN) OF 'IND_TEST_ID' (NON-UNIQUE) (Cost=2Card=9)


SQL> select id from test;

Execution Plan
----------------------------------------------------------
   0      SELECT STATEMENT Optimizer=CHOOSE (Cost=4 Card=30366 Bytes=151830)
   1    0   INDEX (FAST FULL SCAN) OF 'IND_TEST_ID' (NON-UNIQUE) (Cost=4 Card=30366 Bytes=151830)


SQL> select id from test order by id;

Execution Plan
----------------------------------------------------------
   0      SELECT STATEMENT Optimizer=CHOOSE (Cost=26 Card=30366 Bytes=151830)
   1    0   INDEX (FULL SCAN) OF 'IND_TEST_ID' (NON-UNIQUE) (Cost=26 Card=30366 Bytes=1518

 

INDEX (FAST FULL SCAN): 不会按照索引的顺序执行,因此不保证查询结果按照索引排序。

INDEX (FULL SCAN): 根据索引本身的顺序进行扫描。

 关于INDEX FULL SCAN和INDEX FAST FULL SCAN的区别在于,前者在对索引进行扫描的时候会考虑大索引的结构,而且会按照索引的排序,
 而后者则不会,INDEX FAST FULL SCAN不会去扫描根块和分支块,对索引像访问堆表一样访问,所以这两个扫描方式用在不同的场合
 如果存在ORDER BY这样的排序,INDEX FULL SCAN是合适的,如果不需要排序,那INDEX FAST FULL SCAN效率是更高的。

 

index rang scan 是根据索引的叶子block中数据去访问表,和 key 大小顺序一致
index FFS 是根据索引的 extent /block 顺序去访问所有索引block,包括所有叶子和枝节点,这个顺序并不和 key 顺序一致。

 

Index full scan reads the index data in the order of the data. Index fast full scan reads the index blocks in the physical order of the blocks.

http://blog.csdn.net/robinson1988/article/details/4980611

http://blog.itpub.net/6906/viewspace-21696/

posted @ 2016-10-08 22:08  Oracle-fans  阅读(583)  评论(0编辑  收藏  举报