概念:
blevel:二元高度=索引高度-1
clustering_factor:集群因子,扫描index scan得出的要扫描的表中block数,clustering_factor<=table blocks
索引扫描的计算公式:
cost =blevel +
ceil(leaf_blocks *effective index selectivity) +ceil(clustering_factor * effective table selectivity)
SQL> select leaf_blocks,blevel,clustering_factor from dba_indexes where index_name='IDX_T'; LEAF_BLOCKS BLEVEL CLUSTERING_FACTOR ----------- ---------- ----------------- 112 1 776
NUM_ROWS
NUM_DISTINCT NUM_NULLSHIGH_VALUE
LOW_VALUENUM_ROWS-NUM_NULLS
HIGH_VALUE-LOW_VALUE
50736 507351 538202 5073553818
effective index selectivity=(limit-low_value)/(high_value-low_value)
SQL> select (1000-2)/(53820-2) selectivity from dual; SELECTIVITY ----------- 0.018543982
SQL> SELECT OWNER FROM TEST WHERE OBJECT_ID<1000; 已选择953行。 执行计划 ---------------------------------------------------------- Plan hash value: 1810195980 --------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost | --------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 941 | 10351 | 19 | | 1 | TABLE ACCESS BY INDEX ROWID| TEST | 941 | 10351 | 19 | |* 2 | INDEX RANGE SCAN | IDX_T | 941 | | 4 | --------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("OBJECT_ID"<1000)
1.回表io=ceil(clustering_factor * effective table selectivity)=19-4=15
2.blevel +ceil(leaf_blocks *effective index selectivity)
原文:http://blog.csdn.net/hughwang1216/article/details/38627629