Oracle的表压缩

    Oracle压缩数据的处理基于数据库块,其本质上是通过消除在数据库块中的重复数据来实现空间节约,具体方法如下:比较数据块中包含的所有字段或记录,其中重复的数据只在位于数据块开始部分的记号表(Symbol Table)中存储一份,在其他行或字段出现同样的数据时,只记录一个指向记号表中相关数据的指针。

    创建压缩表:

    create table Name(

    ......

    ) compress;

    alter table Name compress;

    alter table Name nocompress;

    

    物化视图的压缩:

    create materialized view ViewName compress

    as select ......;

    alter materialized view ViewName compress;

    

    分区表的压缩:

    create table Name (

    ......

    ) compress

    partition by ......;

    create table Name (

    ......

    )

    partition by ......(

    partition PartName ...... compress,

    partition PartName ...... compress,

    partition PartName ......

    );

    在表空间级别上定义压缩属性:

    create tablespace ...... default compress;

    alter tablespace ...... compress / nocompress;

    当压缩属性被定义在表空间上时,在其中创建表时,该特性将被表继承,但表级别的压缩属性会覆盖表空间的压缩属性。

    

    查看一个表是否为压缩表:

    select compression from user_table where table_name=TableName;

    

    查看一个表空间是否被压缩:

    select def_tab_compression from dba_tablespace where tablespace_name=TablespaceName;

    

    查看分区表各分区的压缩属性:

    select table_name, partition_name, compression from user_tab_partitions where table_name=TableName;

    

    表压缩的实现:

    压缩表的数据要能够被压缩,必须正确地使用批量装载或插入:

    1、在SQL * LOADER中使用直接路径(direct path)装载数据;

    2、执行create table ... as select语句;

    3、执行并行插入语句;

    4、执行串行插入语句并且使用append提示。

    alter table Name move compress / nocompress;

    

    性能分析:

    1、在批量装载或插入数据的过程中,由于压缩的同时进行,会引起CPU使用率提高,及导致装载时间明显增加。

    2、对于普通的INSERT语句,由于没有执行压缩过程,性能几乎没有影响。

    3、用DELETE语句删除压缩表的操作会比较快,主要是因为压缩表中被压缩行的数据比较小,相应的需要写日志的数据量也比较小。

    4、更新压缩的操作会比较慢,主要由于ORACLE对非压缩表执行了一些优化。

    5、在IO吞吐率受限制的系统执行大批量查询,比如全表扫描,压缩表将明显提高查询速度,主要由于压缩后,查找同样的数据行只需要读取更少的数据块。

猜你喜欢

转载自javakill.iteye.com/blog/1844321
今日推荐