复合索引不同建法的选择
2010-10-28 14:19
323 查看
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数据库性能优化》
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数据库性能优化》
相关文章推荐
- mongodb AND查询遇到多个index时候可能会做交集——和复合索引不同
- oracle复合索引的选择和使用
- 复合索引的前导列如何选择?
- 有效使用索引+索引列上所使用的操作符+避免对唯一索引列使用null+选择复合索引主列
- 复合索引顺序选择问题
- mysql(三)复合索引中列的顺序怎么选择提供性能
- MongoDB 复合索引
- 你的选择:学习的不同境界--转自《开复学生网》
- Tips on Optimizing SQL Server Composite Indexes(SQL server 复合索引优化提示)
- 基本CSS选择器,复合选择器,后代选择器
- pandas小记:pandas索引和选择
- MyISAM和InnoDB的索引在实现上的不同
- jquery 如何同时选择多个不同的id执行同一种操作?
- 大数据架构和模式(四)了解用于大数据解决方案的原子模式和复合模式 大数据架构和模式(五)对大数据问题应用解决方案模式并选择实现它的产品
- 复合索引和多个单列索引的效率比较
- 不同机器学习任务深度学习模型的选择
- 1~12月健康食物不同选择
- Selnium用java选择ul中不同顺序的li方式
- PHP使用不同索引的数组
- python-如何根据用户选择实现不同函数功能