ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 读书笔记之-索引压缩

读书笔记之-索引压缩

原创 Linux操作系统 作者:lsq_008 时间:2008-04-21 13:42:05 0 删除 编辑

1. 创建一个索引组织表,但不压缩

sys@TEST>create table iot                                                                   
  2  (owner,object_type,object_name,
  3  constraint iot_pk primary key(owner,object_type,object_name)
  4  )
  5  organization index
  6  nocompress
  7  as 
  8  select distinct owner,object_type,object_name         
  9  from sys.all_objects;
 
Table created.
 
sys@TEST>select count(*) from iot;
 
  COUNT(*)
----------
      2820
 
sys@TEST>analyze index iot_pk validate structure;
 
Index analyzed.
 
sys@TEST>select lf_blks,br_blks,used_space,opt_cmpr_count,opt_cmpr_pctsave from index_stats;
 
   LF_BLKS    BR_BLKS USED_SPACE OPT_CMPR_COUNT OPT_CMPR_PCTSAVE
---------- ---------- ---------- -------------- ----------------
        14          1      94125              2               37

可见,这个未压缩的索引使用了14个叶子块,1个分支块,使用空间为94125字节。另外,建议的最优压缩数为2.

2 。将表重建,并指定compress 为1.
 
sys@TEST>alter table iot move compress 1;
 
Table altered.
 
sys@TEST>select lf_blks,br_blks,used_space,opt_cmpr_count,opt_cmpr_pctsave from index_stats;
 
no rows selected
 
sys@TEST>analyze index iot_pk validate structure;
 
Index analyzed.
 
sys@TEST>select lf_blks,br_blks,used_space,opt_cmpr_count,opt_cmpr_pctsave from index_stats;
 
   LF_BLKS    BR_BLKS USED_SPACE OPT_CMPR_COUNT OPT_CMPR_PCTSAVE
---------- ---------- ---------- -------------- ----------------
        11          1      78121              2               24

可见,压缩数为1时,使用的叶子块为11个,占用空间78121字节,得到了压缩。

3. 再次重建这个表,压缩数指定为2.
 
sys@TEST>alter table iot move compress 2;
 
Table altered.
 
sys@TEST>analyze index iot_pk validate structure;
 
Index analyzed.
 
sys@TEST>select lf_blks,br_blks,used_space,opt_cmpr_count,opt_cmpr_pctsave from index_stats;
 
   LF_BLKS    BR_BLKS USED_SPACE OPT_CMPR_COUNT OPT_CMPR_PCTSAVE
---------- ---------- ---------- -------------- ----------------
         9          1      58864              2                0
 

可见,此时索引得到了最大压缩,只剩下9个叶子块,占用空间58864字节。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/10972173/viewspace-246170/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
十余年大型金融及电信系统数据库管理经验,曾服务于中国建设银行、中国移动。对oracle,mysql数据库有深入了解。 擅长python开发,独立开发了开源数据库自动化监控运维平台Power Monitor。

注册时间:2008-02-29

  • 博文量
    335
  • 访问量
    1369112