索引的压缩除了减少存储空间外,同时也减少了IO次数,减少了缓冲区内存占用。
Oracle 9i在index_stats视图中提供了两列:opt_cmpr_count,opt_cmpr_pctsave ,通过分析索引的结构可以统计出索引的压缩比,以及适合压缩的字段数(如果是用PL SQL DEV多会话模式的话,注意需要在analyze index 的同一会话才能查询index_stats视图的结果)
Declare
Begin
Execute Immediate 'Create table zl_indexes_compress(idxname varchar(100),cnt number,pct number)';
For R In (Select Owner || '.' || Index_Name Idxname From All_Indexes Where Owner = 'ZLHIS' And Rownum<100) Loop
Execute Immediate 'analyze index ' || R.Idxname || ' validate Structure';
Execute Immediate 'Insert Into zl_indexes_compress Select :x,opt_cmpr_count,opt_cmpr_pctsave From index_stats' Using R.Idxname;
End Loop;
Commit;
End;
/
SQL> Select * From zl_indexes_compress Order By pct Desc;