创建压缩索引
从串联索引中去掉冗余
压缩索引特征:
每个条目分为两项:前缀和后缀
前缀:建立在串联索引的前几列,这些列有许多值重复
后缀:索引键后几列,是前缀索引所在索引中唯一部分。
create table ind_test as select * from all_objects;
drop table id_stats;
create table id_stats as select 'compress 33333' what ,t.* from index_stats t where 1=0;
drop index ind_compress;
create index ind_compress on ind_test(owner,object_type,object_name);
analyze index ind_compress validate structure;
analyze index ind_compress compute statistics;
insert into id_stats select 'compress 0',t.* from index_stats t ;
drop index ind_compress;
create index ind_compress on ind_test(owner,object_type,object_name) compress 1;
analyze index ind_compress validate structure;
analyze index ind_compress compute statistics;
insert into id_stats select 'compress 1',t.* from index_stats t ;
drop index ind_compress;
create index ind_compress on ind_test(owner,object_type,object_name) compress 2;
analyze index ind_compress validate structure;
analyze index ind_compress compute statistics;
insert into id_stats select 'compress 2',t.* from index_stats t ;
drop index ind_compress;
create index ind_compress on ind_test(owner,object_type,object_name) compress 3;
analyze index ind_compress validate structure;
analyze index ind_compress compute statistics;
insert into id_stats select 'compress 3',t.* from index_stats t ;
官网上说是分析后压缩节省空间:但是我认为是在最佳压缩方案下,在当前基础上还能节省空间
压缩会增加CPU计算,不光光维护还有查询也是的。这需要开发者在IO和CPU计算做出一个权衡。
利用压缩能够减少该索引的缓冲块的个数,从而减少IO次数,增加CPU次数,增加对索引竞争
如果当前大量占用CPU时间,使用索引压缩会适得其反,降低查询速度
如果当前大量IO,使用压缩索引键会提高性能