2011年7月19日火曜日

[索引相关] 索引键压缩

索引键压缩
- 每个索引键条目分为2部分,“前缀”“后缀”,前缀在串联索引的前几列(有重复值),后缀在索引键的后几列(有区别的部分)
- 压缩可以节省索引存储空间,但对于索引维护增加负担
- 压缩后检索时会减少IO,但会占用更多的cpu时间,如果现在已经在用大量的cpu时间,利用压缩可能会适得其反
 
sys@XE> create table t as select * from all_objects;
表が作成されました。

sys@XE> create index t_idx on t(owner,object_type,object_name);
索引が作成されました。

sys@XE> analyze index t_idx validate structure;
索引が分析されました。

sys@XE> create table idx_stats as select 'noncompressed' what,a.* from index_stats a;
表が作成されました。

sys@XE> drop index t_idx;
索引が削除されました。

sys@XE> create index t_idx on t(owner,object_type,object_name) compress &1;
1に値を入力してください: 1
旧   1: create index t_idx on t(owner,object_type,object_name) compress &1
新   1: create index t_idx on t(owner,object_type,object_name) compress 1 --- 压缩索引键中的列1
索引が作成されました。

sys@XE> analyze index t_idx validate structure;
索引が分析されました。

sys@XE> insert into idx_stats select 'compress &1',a.* from index_stats a;
1に値を入力してください: 1
旧   1: insert into idx_stats select 'compress &1',a.* from index_stats a
新   1: insert into idx_stats select 'compress 1',a.* from index_stats a
1が作成されました。

sys@XE> drop index t_idx;
索引が削除されました。

sys@XE> create index t_idx on t(owner,object_type,object_name) compress &1;
1に値を入力してください: 2
旧   1: create index t_idx on t(owner,object_type,object_name) compress &1
新   1 create index t_idx on t(owner,object_type,object_name) compress 2 --- 压缩索引键中的列2
索引が作成されました。

sys@XE> analyze index t_idx validate structure;
索引が分析されました。

sys@XE> insert into idx_stats select 'compress &1',a.* from index_stats a;
1に値を入力してください: 2
旧   1: insert into idx_stats select 'compress &1',a.* from index_stats a
新   1: insert into idx_stats select 'compress 2',a.* from index_stats a
1が作成されました。

sys@XE> drop index t_idx;
索引が削除されました。

sys@XE> create index t_idx on t(owner,object_type,object_name) compress &1;
1に値を入力してください: 3
旧   1: create index t_idx on t(owner,object_type,object_name) compress &1
新   1: create index t_idx on t(owner,object_type,object_name) compress 3 --- 压缩索引键中的列3
索引が作成されました。

sys@XE> analyze index t_idx validate structure;
索引が分析されました。

sys@XE> insert into idx_stats select 'compress &1',a.* from index_stats a;
1に値を入力してください: 3
旧   1: insert into idx_stats select 'compress &1',a.* from index_stats a
新   1: insert into idx_stats select 'compress 3',a.* from index_stats a
1が作成されました。

sys@XE> select what,height,lf_blks,br_blks,btree_space,opt_cmpr_count,opt_cmpr_pctsave from idx_stats;

WHAT          HEIGHT   LF_BLKS  BR_BLKS  BTREE_SPACE OPT_CMPR_COUNT OPT_CMPR_PCTSAVE
-------------    ---------- ---------- ----------  -------------  ----------------- --------------------
noncompressed 2       71       1         575744      2             30
compress 1    2       62       1         503532      2             18
compress 2    2       50       1         407628      2             0 --- 最优压缩比,能节省30%空间
compress 3    2       81       1         655380      2             37

4行が選択されました。

0 件のコメント:

コメントを投稿