在多列上创建索引时列的顺序对索引大小的影响

一下内容来自《oracle9i&10g编程艺术》

create table t
as
select * from all_objects;

在owner、object_type、object_name这三列上创建索引,这三列基数大小关系为object_name > object_type > owner


create index t_idx1 on t(owner, object_type, object_name)
/
create index t_idx2 on t(object_name, object_type, owner)
/


naruto@ORCL> select count(distinct owner), count(distinct object_type),
  2   count(distinct object_name), count(*)
  3  from t
  4  /

COUNT(DISTINCTOWNER) COUNT(DISTINCTOBJECT_TYPE) COUNT(DISTINCTOBJECT_NAME)   COUNT(*)
-------------------- -------------------------- -------------------------- ----------
                  27                         35                      29634      49994


naruto@ORCL>analyze index t_idx1 validate structure
  2  /

索引已分析

naruto@ORCL>select btree_space, pct_used, opt_cmpr_count, opt_cmpr_pctsave
  2   from index_stats;

BTREE_SPACE   PCT_USED OPT_CMPR_COUNT OPT_CMPR_PCTSAVE
----------- ---------- -------------- ----------------
    2792096         89              2               28


naruto@ORCL>analyze index t_idx2 validate structure
  2  /

索引已分析

naruto@ORCL>select btree_space, pct_used, opt_cmpr_count, opt_cmpr_pctsave
  2   from index_stats;

BTREE_SPACE   PCT_USED OPT_CMPR_COUNT OPT_CMPR_PCTSAVE
----------- ---------- -------------- ----------------
    2792096         89              1               13     
     
     
由OPT_CMPR_COUNT和OPT_CMPR_PCTSAVE这两列就很容易的看出t_idx1的最优压缩数为2,可以压缩28%的空间。t_idx2的最优压缩数为1,可以压缩13%的空间。把基数小的列放在创建索引时的前面可以减少空间的利用率。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/25361369/viewspace-697521/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/25361369/viewspace-697521/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值