码迷,mamicode.com
首页 > 其他好文 > 详细

INDEX SKIP SCAN适用场景

时间:2017-11-11 11:32:35      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:mit   access   red   lin   bytes   comm   com   filter   commit   

--请记住这个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适用场景

标签:mit   access   red   lin   bytes   comm   com   filter   commit   

原文地址:http://www.cnblogs.com/Clark-cloud-database/p/7818266.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!