INDEX SKIP SCAN适用场景
Posted ClarkYu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了INDEX SKIP SCAN适用场景相关的知识,希望对你有一定的参考价值。
--请记住这个INDEX SKIP SCAN扫描方式
drop table t purge;
create table t as select * from dba_objects;
update t set object_type=‘TABLE‘ ;
commit;
update t set object_type=‘VIEW‘ where rownum<=30000;
commit;
create index idx_type_id on t(object_type,object_id);
exec dbms_stats.gather_table_stats(ownname => ‘LJB‘,tabname => ‘T‘,estimate_percent => 10,method_opt=> ‘for all indexed columns‘,cascade=>TRUE) ;
set autotrace traceonly
set linesize 1000
select * from t where object_id=8;
执行计划
-------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 94 | 4 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T | 1 | 94 | 4 (0)| 00:00:01 |
|* 2 | INDEX SKIP SCAN | IDX_TYPE_ID | 1 | | 3 (0)| 00:00:01 |
-------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("OBJECT_ID"=8)
filter("OBJECT_ID"=8)
统计信息
----------------------------------------------------------
1 recursive calls
0 db block gets
7 consistent gets
0 physical reads
0 redo size
1401 bytes sent via SQL*Net to client
415 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
总结:
复合索引当谓词条件不为索引的第一个字段时,一般不会走索引,但是当复合索引的第一个字段重复率较高时,会用到INDEX SKIP SCAN(记得收集统计信息让oracle知道列的分布情况)。
以上是关于INDEX SKIP SCAN适用场景的主要内容,如果未能解决你的问题,请参考以下文章