create index idx_a02 on A02 (owner, object_type, object_name);
analyze table a02 compute statistics;
select t.leaf_blocks from user_indexes t where t.index_name='IDX_A02';
29
drop index idx_a02;
create index idx_a02 on A02 (owner, object_type, object_name) compress 1;
analyze table a02 compute statistics;
select t.leaf_blocks from user_indexes t where t.index_name='IDX_A02';
25
drop index idx_a02;
create index idx_a02 on A02 (owner, object_type, object_name) compress 2;
analyze table a02 compute statistics;
select t.leaf_blocks from user_indexes t where t.index_name='IDX_A02';
20
drop index idx_a02;
create index idx_a02 on A02 (owner, object_type, object_name) compress 3;
analyze table a02 compute statistics;
select t.leaf_blocks from user_indexes t where t.index_name='IDX_A02';
33
可以看出当compress为0,1,2时叶块一次减少,但当compress为3时比没有compress时占用的叶块更多。
这是因为owner,object_type都有比较多的重复值,而object_name时唯一的。oracle在做compress时会为每个唯一的值增加4bytes的开销,
比如组合索引(x,y),x占用1byte,y占用60bytes,共100条,x都是同样的值而y是唯一的。没有compress时,占用空间为61x100=6100。
当做compress 2时占用的空间为1+4+(60+4)x100=6405。所以会比no compress占用更多空间。
使用compress index会增加cpu使用,但每个叶块存放更多的索引条目,增加buffer hit ratio,减少physical read,但是也会增加block contention的出现机率。