Trang chủ   Khách hàng đăng nhập   Đối tác đăng nhập   Liên hệ Tìm kiếm:  
   
Đào tạo Giải pháp Kiến thức Tin tức Giới thiệu

Kỹ thuật nén trong Oracle 10g & 11g

Giới thiệu

Oracle 10g chỉ hỗ trợ khả năng nén khi ghi dữ liệu theo “khối”. Cụ thể cho những thao tác sau:

  1. Direct Load với SQL*Loader
  2. CREATE TABLE … AS SELECT
  3. Direct INSERT
  4. ALTER TABLE … MOVE

Oracle 11g đã cải tiến kỹ thuật nén để hỗ trợ thêm cho thao tác lệnh DML (Insert, Update, Delete). Cấu hình nén DML bằng cách dùng chỉ thị lệnh sau ở mức Partition hoặc Table hoặc Tablespace:

  1. 11gR1: COMPRESS FOR ALL OPERATIONS
  2. 1gR2: COMPRESS FOR OLTP

Mã minh họa

Ví dụ sau minh họa khả năng nén trong Oracle 10g:

[oracle@localhost ~]$ oracleviet

SQL*Plus: Release 10.2.0.1.0 - Production on Sat Jul 23 04:49:59 2011

 

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

 

Connected to:

Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, Oracle Label Security, OLAP and Data Mining options

oracleviet@ORA10G> drop table big_table;

 

oracleviet@ORA10G> create table big_table as selecT * from all_objects;

 

Table created.

 

oracleviet@ORA10G>

oracleviet@ORA10G> select sum(bytes/1024/1024) from dba_segments where segment_name='BIG_TABLE'

  2  /

 

SUM(BYTES/1024/1024)

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

                   6

 

oracleviet@ORA10G>

oracleviet@ORA10G> alter table big_table move compress

  2  /

 

Table altered.

 

oracleviet@ORA10G>

oracleviet@ORA10G> select sum(bytes/1024/1024) from dba_segments where segment_name='BIG_TABLE'

  2  /

 

SUM(BYTES/1024/1024)

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

                   2

 

Ví dụ sau minh họa kỹ thuật nén cho thao tháo INSERT bình thường trong Oracle 11g:

[oracle@oraserver ~]$ oracleviet

 

SQL*Plus: Release 11.2.0.1.0 Production on Thu Nov 3 10:34:23 2011

 

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

 

 

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

 

oracleviet@orcl> @11g_compress.sql

oracleviet@orcl>

oracleviet@orcl> drop table big_table;

 

Table dropped.

 

oracleviet@orcl> create table big_table as select * from all_objects where 1=0;

 

Table created.

 

oracleviet@orcl>

oracleviet@orcl> set timing on

oracleviet@orcl> begin

  2   for i in (select * from all_objects) loop

  3          insert into big_table values i; -- NORMAL insert

  4   end loop;

  5   commit;

  6  end;

  7  /

 

PL/SQL procedure successfully completed.

 

Elapsed: 00:00:16.83

oracleviet@orcl> set timing off

oracleviet@orcl>

oracleviet@orcl> select sum(bytes/1024/1024) MB from dba_segments where segment_name='BIG_TABLE'

  2  /

 

        MB

----------

         8

 

oracleviet@orcl>

oracleviet@orcl>

oracleviet@orcl> PROMPT #######COMPRESS FOR OLTP#######

#######COMPRESS FOR OLTP#######

oracleviet@orcl>

oracleviet@orcl> alter table big_table compress for oltp;

 

Table altered.

 

oracleviet@orcl>

oracleviet@orcl> select sum(bytes/1024/1024) MB from dba_segments where segment_name='BIG_TABLE'

  2  /

 

        MB

----------

         8

 

oracleviet@orcl>

oracleviet@orcl> truncate table big_table;

 

Table truncated.

 

oracleviet@orcl>

oracleviet@orcl> set timing on

oracleviet@orcl> begin

  2   for i in (select * from all_objects) loop

  3          insert into big_table values i; -- NORMAL insert

  4   end loop;

  5   commit;

  6  end;

  7  /

 

PL/SQL procedure successfully completed.

 

Elapsed: 00:00:36.32

oracleviet@orcl> set timing off

oracleviet@orcl>

oracleviet@orcl> select sum(bytes/1024/1024) MB from dba_segments where segment_name='BIG_TABLE'

  2  /

 

        MB

----------

         3

 

oracleviet@orcl>

 

(11/2011 - Sưu tầm: http://oracleviet.blogspot.com/ )

Tham khảo

 

VietPace chuyên cung cấp giải pháp và khóa đào tạo về CNTT&TT, đặc biệt chúng tôi tiên phong về lĩnh vực bảo mật Oracle tại Việt Nam, để biết thêm thông tin xin vui lòng liên hệ tại:

 

 



Copyright 2010, www.vietpace.com, All rights reserved.