压缩表

(1)基本表压缩
SQL> create table combasic compress basic as select * from dba_objects;

Table created.
(2)oltp表压缩
SQL> create table comoltp compress for oltp as select * from dba_objects;

Table created.

SQL> create table nocom as select * from dba_objects;

Table created.
查看表是不是压缩了,压缩的类型
SQL> select table_name,compression,compress_for from user_tables;

TABLE_NAME               COMPRESS COMPRESS_FOR
------------------------------ -------- ------------
TT                   ENABLED    BASIC
TTT                   ENABLED    OLTP
DEPT                   DISABLED
EMP                   DISABLED
BONUS                   DISABLED
SALGRADE               DISABLED
SYS_TEMP_FBT               DISABLED   BASIC

SQL> select segment_name,sum(bytes)/1024 KB from user_extents
  2  where segment_name in ('NOCOM','COMBASIC','COMOLTP')
  3  group by segment_name;

SEGMENT_NAME                 KB
-------------------- ----------
COMBASIC                   3072
COMOLTP                    3072
NOCOM                      9216

SQL> select 9216/3072 from dual;

 9216/3072
----------
         3

SQL> update NOCOM set object_name=object_name||'ABC';

72667 rows updated.

SQL> update COMBASIC set object_name=object_name||'ABC';

72665 rows updated.

SQL> update COMOLTP set object_name=object_name||'ABC';

72666 rows updated.

SQL> commit;

Commit complete.

SQL> select segment_name,sum(bytes)/1024 KB from user_extents
  2  where segment_name in ('NOCOM','COMBASIC','COMOLTP')
  3  group by segment_name;

SEGMENT_NAME                 KB
-------------------- ----------
COMBASIC                   8192
COMOLTP                    5120
NOCOM                      9216


alter tablespace users default compress ;
select tablespace_name , compress_for from dba_tablespaces where tablespace_name='USERS' ;
create table   ttt (id number) tablespace users ;
create table   ttt2 (id number) tablespace users nocompress ;
select table_name , COMPRESS_FOR from user_tables where table_name in ('TTT','TTT2') ;
alter tablespace users default nocompress ;
select tablespace_name , compress_for from dba_tablespaces where tablespace_name='USERS' ;

2. Basic compression
要点1:数据压缩只在direct path load的时候才会生效,对于普通的dml语句insert、update不会发生压缩。
要点2:压缩的时候为了保证最大程度的压缩,会自动设置pctfree为0(不是强制的,也可以在建表的时候设置pctfree为其他值)。
create table t(id number) compress ;
create table t(id number) compress basic ;这两个一样basic

3. OLTP compression
要点1:不像Basic compression,OLTP compression会对所有的dml生效,所以适用于OLTP系统。
要点2:自动设置pctfree为10,也可以自行设置。
要点3:oracle数据库内部的压缩动作不是在所有dml操作中都产生,只有当新的block中的数据存放到达了厥值的时候才会引发块内的压缩操作。
这里重点描述一下第三个要点:
oracle 数据库压缩数据块在批量模式下,而不是每个更改数据的操作都会引发压缩操作。
block中保留未压缩的数据达到了一个厥值的时候会引发块内的压缩操作。
当一个事务导致在block中的数据达到了厥值,所有的block中的内容就会被压缩。然后,更多的数据加入到块中,再一次达到厥值,整个block会重新压缩,以达到最大程度的压缩级别。这个过程会一直重复,直到oracle 数据库确定无法再从压缩上获得更高的效益。只有某些触发压缩条件的的事务会经历轻微的压缩开销。
所以多数oltp事务作用在压缩的块上面,会和未压缩的表上拥有相同的性能。
只有那些比较倒霉的操作会引发块内的压缩动作。


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值