oracle IOT表学习

本文介绍了Index-Organized Table(IOT)的概念及其创建方法,并通过实例展示了如何分析IOT表的压缩度以及如何调整压缩级别来优化存储空间。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

IOT: Index-Organized Table
索引组织表
含义即将表结构整体放入索引中,且是按照主键进行排序的。
创建:
create table emp_iot(
    emp_no int,
    emp_name varchar2(100),
    dept_no int,
    salary number(10,2),
    constraint pk_empi primary key(emp_no, emp_name, dept_no))
organization index
[pctthreshold n/including colname] overflow tablespace fund_index;

参数:
pctthreshold: 溢出阀值。指定当块中的使用空间达到该值时,将溢出的数据存放到另外的段上。由参数overflow指定。
including:指定在哪个字段以后的字段放入溢出段。由参数overflow指定溢出的表空间。

分析该表的压缩度:
analyze table emp_iot validate structure cascade;
or
analyze index pk_empi validate structure;

查看分析结果

--将表改为非压缩模式:
SQL> alter table iot move nocompress;
 
Table altered
--分析索引
SQL> analyze index pk_iot validate structure;
 
Index analyzed
 
查看分析结果:
SQL> select ie.name, ie.used_space, ie.used_space*(1-ie.opt_cmpr_pctsave/100) after_compress,
  2         ie.pct_used, ie.opt_cmpr_count, ie.opt_cmpr_pctsave
  3    from index_stats ie
  4  /
 
NAME                           USED_SPACE AFTER_COMPRESS   PCT_USED OPT_CMPR_COUNT OPT_CMPR_PCTSAVE
------------------------------ ---------- -------------- ---------- -------------- ----------------
PK_IOT                            2672239      1870567.3         90              2               30
 
 字段used_space标识该索引使用了多少空间。
opt_cmpr_count是一个压缩建议值,表明压缩度为2时,可以节约30%的空间。
也就是压缩后空间可减少到:used_space*(1-30%),即:1870567.3
现在将压缩度改至2,看结果如何:
SQL> alter table iot move compress 2;
 
Table altered

--分析索引
SQL> analyze index pk_iot validate structure;
 
Index analyzed
 
--查看压缩结果:
SQL> select ie.name, ie.used_space, ie.used_space*(1-ie.opt_cmpr_pctsave/100) after_compress,
  2         ie.pct_used, ie.opt_cmpr_count, ie.opt_cmpr_pctsave
  3    from index_stats ie
  4  /
 
NAME                           USED_SPACE AFTER_COMPRESS   PCT_USED OPT_CMPR_COUNT OPT_CMPR_PCTSAVE
------------------------------ ---------- -------------- ---------- -------------- ----------------
PK_IOT                            1858487        1858487         89              2                0

可以看到现在已经压缩到1858487,与之前计算的1870567.3的估计值很接近。
压缩IOT不仅可以节省空间,还可以加快SQL语句的执行速度。
缺点就是在创建或压缩的时候需要占用比不压缩更多的CPU和时间。
但是从长远来看,这种消耗实际上是值得的。

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

转载于:http://blog.itpub.net/12932950/viewspace-629852/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值