表壓縮技術

wei-xh發表於2011-03-02

我們為了降低表的大小,一般有以下兩個手段

1) 降低表的pctfree值。極端的情況可以是0

2) 採用表的壓縮技術,即在表建立的時候顯式的指定compress關鍵詞。

 

讓我們看看壓縮的效果:

1) 普通方式的建立表142 M

vodka@CRMG>create table wxh_tbd1 as select * from bpm_actinst;

 

Table created.

vodka@CRMG>@size

 

142M

 

2) pctfree0方式建立128M

vodka@CRMG>create table wxh_tbd2 pctfree 0 as select * from bpm_actinst;

 

Table created.

vodka@CRMG>@size

 

128M

 

3) 增加compress關鍵字 33M

vodka@CRMG>create table wxh_tbd3 compress as select * from bpm_actinst;

 

Table created.

 

vodka@CRMG>@size

 

33M

 

4) 增加compress關鍵字,並且按照重複度較高的欄位排序。21M.

vodka@CRMG>create table wxh_tbd4 compress as select * from bpm_actinst order by col2,actor,node_type;

 

Table created.

 

vodka@CRMG>@size

 

21M

 

預設的啟用了compress,表的pctfree屬性就是0

vodka@CRMG>vodka@CRMG>vodka@CRMG>@getddl

Enter value for object_type: table

Enter value for object_name: wxh_tbd4

Enter value for owner: vodka

old   1: select dbms_metadata.get_ddl(upper('&object_type'),upper('&object_name'),upper('&owner')) FROM DUAL

new   1: select dbms_metadata.get_ddl(upper('table'),upper('wxh_tbd4'),upper('vodka')) FROM DUAL

 

DBMS_METADATA.GET_DDL(UPPER('TABLE'),UPPER('WXH_TBD4'),UPPER('VODKA'))

--------------------------------------------------------------------------------

 

  CREATE TABLE "VODKA"."WXH_TBD4"

   (    "ID" NUMBER(19,0) NOT NULL ENABLE,

        "GMT_MODIFIED" DATE,

        "MODIFIER" VARCHAR2(32),

        "IS_DELETED" CHAR(1) NOT NULL ENABLE,

        "VERSION" NUMBER NOT NULL ENABLE,

        "PROCINST" NUMBER(19,0),

        "SIGN_FLAG" VARCHAR2(32),

        "STATE" VARCHAR2(255),

        "FLAG" VARCHAR2(32),

        "START_TIME" DATE,

        "END_TIME" DATE,

        "NODE_NAME" VARCHAR2(255),

        "NODE_TYPE" VARCHAR2(32),

        "OLD_ACTID" NUMBER(19,0),

        "SUPER_ACTID" NUMBER(19,0),

        "PATH" VARCHAR2(512),

        "ACTOR" VARCHAR2(64),

        "ORG_ROLE" VARCHAR2(64),

        "BAK_ACTOR" VARCHAR2(64),

        "TASK_ORGPATH" VARCHAR2(255),

        "TASK_TITLE" VARCHAR2(512),

        "TASK_LEVEL" VARCHAR2(32),

        "TASK_SRC" VARCHAR2(64),

        "TASK_TYPE" VARCHAR2(32),

        "SERVICE_METHOD" VARCHAR2(32),

        "ASSIGN_TIME" DATE,

        "RESERVED_TIME" DATE,

        "DEADLINE_TIME" DATE,

        "TAKEOVER_TIME" DATE,

        "APPROVAL_ID" VARCHAR2(64),

        "APPROVAL_ORG" VARCHAR2(255),

        "APPROVAL_ROLE" VARCHAR2(255),

        "APPROVAL_TIME" DATE,

        "APPROVAL_NAME" VARCHAR2(255),

        "APPROVAL_VOTE" VARCHAR2(64),

        "APPROVAL_MEMO" VARCHAR2(4000),

        "COL1" DATE,

        "COL2" VARCHAR2(255),

        "COL3" VARCHAR2(255),

        "ARRANGE_TYPE" VARCHAR2(255),

        "TASK_NOTE" VARCHAR2(4000),

        "NODE_CATEGORY" VARCHAR2(255),

        "COL4" VARCHAR2(255),

        "COL5" VARCHAR2(255)

   ) PCTFREE 0 PCTUSED 40 INITRANS 1 MAXTRANS 255 COMPRESS LOGGING

  STORAGE(INITIAL 1048576 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645

  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)

  TABLESPACE "VODKA"

 

壓縮表的適用場景及特點

1) 大大減少表儲存空間,我們的例子中壓縮了近六倍的空間。

2) 比較適合靜態表,多見於資料倉儲,,比如備份表,或者表上只有deleteinsert操作,沒有update操作,原因很簡單由於pctfree0update導致的行連結會大大增加。

3) 壓縮表比一般的表在讀取資料塊的時候耗取更多的CUP,不過11G的文件上宣稱,這種限制在11G已經不存在了。在實際應用中需要權衡。

 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22034023/viewspace-688255/,如需轉載,請註明出處,否則將追究法律責任。

相關文章