索引压缩的好处:
- 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 压缩两列,看看压缩两列和一列在使用空间上有多大区别
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