索引的压缩



索引压缩的好处:
  • Fewer index leaf blocks need to be read since more rows fit into fewer blocks
  • Insert statements are faster since fewer leaf blocks need to be read to determine where the new row is inserted
  • Faster full index scans due to fewer leaf blocks
  • Space savings

compress1 只压缩索引列的第一列
compress2 压缩两列,看看压缩两列和一列在使用空间上有多大区别

对于唯一索引,前缀索引长度是1到(列数-1),表上压缩的列数,默认是压缩列数-1
对于非唯一索引,前缀的长度是1到列数,表上压缩的列数,默认是压缩列数


You cannot specify  COMPRESS  for a bitmap index.位图索引不能压缩


SQL> create index ind_t on t(empno) compress 1 ;
索引已创建。
SQL> select index_name,compression From user_indexes where table_name in ('T','T1','T2','T3');
INDEX_NAME COMPRESS
------------------------------ --------
IND_T ENABLED


取消索引的压缩:
SQL> alter index ind_t rebuild NOCOMPRESS;
索引已更改。

修改索引为压缩索引:
SQL> alter index ind_t rebuild COMPRESS 1;
索引已更改。

如果超过了了,索引列数,就会报错:
SQL> alter index ind_t rebuild COMPRESS 2;
alter index ind_t rebuild COMPRESS 2
*
第 1 行出现错误:
ORA-25194: 无效的 COMPRESS 前缀长度值


索引的压缩:

SQL> create index ind_t4 on t4(empno,ename)  tablespace compress01;
索引已创建。
SQL> create index ind_t5 on t5(empno,ename)  compress tablespace compress01;
索引已创建。
SQL> select index_name,compression ,leaf_blocks,tablespace_name From user_indexes  where table_name in ('T4','T5');
INDEX_NAME                     COMPRESS LEAF_BLOCKS TABLESPACE_NAME
------------------------------ -------- ----------- ------------------------------------------------------------
IND_T5                         ENABLED          303 COMPRESS01
IND_T4                         DISABLED         573 COMPRESS01
结论:虽然我们是在压缩表空间里创建索引,但是索引仍然是disabled,没有压缩,所有如果要压缩索引,必须手动指明compress

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值