复合索引不同建法的选择

create index ind_old on test(a,b,c,d) tablespace tbsindex compress 2;
select segment_name,bytes,blocks from user_segments where segment_name='IND_OLD';
set autotrace trace;
--重建复合索引中列的排列情况选择
--查询各个列的distinct值
select count(distinct b) from test;
338965
select count(distinct a) from test;
1148
select count(distinct c) from test;
2
select count(distinct d) from test;
5
--页索引里列平均存储长度。
select avg(vsize(b)) from test;
7字节
select avg(vsize(c)) from test;
2字节
select avg(vsize(a)) from test;
5.5字节
select avg(vsize(d)) from test;
1.67字节

---根据以上信息计算页索引所需要的空间
index1:(b,c,a,d) compress 2
B:distinct number---338965
C:distinct number---2
index size=338965*2*(7+2)+537351*(1.7+5.5+6)=14603998

index2:(c,a,b,d) compress 2
B:distinct number---2
A:distinct number---1148
index size=2*1148*(2+5.5)+537351*(7+1.7+6)=7916279

index3:(c,d,a,b) compress 2
C:distinct number---2
D:distinct number---5
index size=2*5*(2+1.7)+537351*(7+5.5+6)=9941030
--可见index2的索引最小。
--这是一个估算公式,索引的空间大小还可以通过user_segments等视图查询,compress 2的时候页索引:size=前导列1数*前导列2数(前导列1位长+前导列2位长)+所有记录数*(第3列位长+第4列位长+6)+overhead,这里的6是rowid在索引里面的存储位长。
create index idx_auction_browse on test(c,a,b,d) tablespace tbsindex compress 2;

————《Oracle数据库性能优化》

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值