1、索引结构。第一张图是索引的官方图解,右侧是存储方式的图解。

oracle 优化——索引与组合索引oracle 优化——索引与组合索引

图中很清晰的展示了索引存储的状况。

在leaf 节点中存储了一列,索引所对应项的 :值,rowId,长度,头信息(控制信息)

这样我们就能很清楚、如果通过索引查找数据,而只需要这个索引的值的时候,写上列名,就可以不需要回表。

2、索引在一般的数据量情况下,只有三层。leaf 是目录,branch 是目录的目录。可以做一个测试

 1 drop table t1 purge;
 2 drop table t2 purge;
 3 drop table t3 purge;
 4 drop table t4 purge;
 5 drop table t5 purge;
 6 drop table t6 purge;
 7 drop table t7 purge;
 8 
 9 
10 create table t1 as select rownum as id ,rownum+1 as id2,rpad('*',1000,'*') as contents from dual connect by level<=1;
11 create table t2 as select rownum as id ,rownum+1 as id2,rpad('*',1000,'*') as contents from dual connect by level<=10;
12 create table t3 as select rownum as id ,rownum+1 as id2,rpad('*',1000,'*') as contents from dual connect by level<=100;
13 create table t4 as select rownum as id ,rownum+1 as id2,rpad('*',1000,'*') as contents from dual connect by level<=1000;
14 create table t5 as select rownum as id ,rownum+1 as id2,rpad('*',1000,'*') as contents from dual connect by level<=10000;
15 create table t6 as select rownum as id ,rownum+1 as id2,rpad('*',1000,'*') as contents from dual connect by level<=100000;
16 create table t7 as select rownum as id ,rownum+1 as id2,rpad('*',1000,'*') as contents from dual connect by level<=1000000;
17 
18 
19 create index idx_id_t1 on t1(id);
20 create index idx_id_t2 on t2(id);
21 create index idx_id_t3 on t3(id);
22 create index idx_id_t4 on t4(id);
23 create index idx_id_t5 on t5(id);
24 create index idx_id_t6 on t6(id);
25 create index idx_id_t7 on t7(id);
26 
27 set linesize 1000
28 set autotrace off
29 select index_name,
30           blevel,
31           leaf_blocks,
32           num_rows,
33           distinct_keys,
34           clustering_factor
35      from user_ind_statistics
36     where table_name in( 'T1','T2','T3','T4','T5','T6','T7');
37 
38 索引的名字          层级     leaf 块
39 INDEX_NAME  BLEVEL LEAF_BLOCKS   NUM_ROWS DISTINCT_KEYS CLUSTERING_FACTOR
40 ------------------ ----------- ---------- ------------- -----------------
41 IDX_ID_T1        0           1          1             1                 1
42 IDX_ID_T2        0           1         10            10                 2
43 IDX_ID_T3        0           1        100           100                15
44 IDX_ID_T4        1           3       1000          1000               143
45 IDX_ID_T5        1          21      10000         10000              1429
46 IDX_ID_T6        1         222     100000        100000             14286
47 IDX_ID_T7        2        2226    1000000       1000000            142858
View Code

相关文章: