Try 11g OLTP compress

December 28th, 2007 | Categories: Boring | Tags:

Oracle11g增加了很多压缩的功能,如对OLTP操作下表压缩的完善,Data Pump 文件的压缩,standby日志传输的压缩,RMAN备份的压缩。

10g之前指定表的compress选项,只能在direct path load或者table move的时候进行压缩

11g中指定compress for all operations则增加了对表压缩的条件。如orawh所总结,

oracle改变了压缩的行为,不是每次发生数据变化都会去压缩,而是通过内部的threshold来控制压缩,并且压缩是由transaction触发的,当一个transaction触发DML操作,oracle会去根据threshold来判断是否需要对整个BLOCK进行compress,如果compress后又到达threshold,那么oracle会再去recompress整个BLOCK,直到oracle觉得没有可压缩的余地,而且只有触发compress的transaction会有一些压缩的代价。

测试如下,

  1. SQL> create table test_compress (id number, name varchar2(3000)) compress for all operations;
  2. Table created.
  3.  
  4. SQL> begin
  5.   2  for i in 1..10000 loop
  6.   3  insert into test_compress values(i,lpad('test',3000,'x') );
  7.   4  commit;
  8.   5  end loop;
  9.   6  end;
  10.   7  /
  11. PL/SQL procedure successfully completed
  12.  
  13. SQL>analyze table test_compress estimate statistics;
  14. Table analyzed.
  15.  
  16. SQL> select  table_name,blocks from dba_tables where table_name='TEST_COMPRESS';
  17. TABLE_NAME     BLOCKS
  18. ---------- ----------
  19. TEST_COMPRESS        118
  20.  
  21.  
  22. SQL> drop table test_compress;
  23. Table dropped.
  24.  
  25. SQL> create table test_compress (id number, name varchar2(3000)) compress for all operations;
  26. Table created.
  27.  
  28. SQL> begin
  29.   2  for i in 1..10000 loop
  30.   3  insert into test_compress values(i,lpad('test',3000,'x') );
  31.   4  end loop;
  32.   5  end;
  33.   6  /
  34. PL/SQL procedure successfully completed.
  35. SQL>commit;
  36. Commit complete
  37.  
  38. SQL>analyze table test_compress estimate statistics;
  39. Table analyzed.
  40.  
  41. SQL> select table_name,blocks from dba_tables where table_name='TEST_COMPRESS';
  42. TABLE_NAME     BLOCKS
  43. ---------- ----------
  44. TEST_COMPRESS       5032
  45.  
  46. SQL> alter table test_compress move;
  47. Table altered.
  48.  
  49. SQL> analyze table test_compress estimate statistics;
  50. Table analyzed.
  51.  
  52.  
  53. SQL>select  table_name,blocks from dba_tables where table_name='TEST_COMPRESS'
  54. TABLE_NAME     BLOCKS
  55. ---------- ----------
  56. TEST_COMPRESS         59

如上测试,由transaction来触发压缩,并且只针对DML操作touch的block进行压缩。

且频繁的更新操作会导致表上有较多的Chained Rows

  1. SQLcreate index idx2 on test_compress(id);
  2. Index created.
  3.  
  4. SQL> begin
  5.   2  for i in 1..1000 loop
  6.   3  update test_compress set id=id+i+40000 where id=i;
  7.   4  commit;
  8.   5  end loop;
  9.   6  end;
  10.   7  /
  11.  
  12. PL/SQL procedure successfully completed.
  13.  
  14. SQL> analyze table test_compress estimate statistics;
  15. Table analyzed.
  16.  
  17. SQL> select  table_name,blocks from dba_tables where table_name='TEST_COMPRESS';
  18. TABLE_NAME     BLOCKS
  19. ---------- ----------
  20. TEST_COMPRESS         59
  21.  
  22. SQL> begin
  23.   2  for i in 1..10000 loop
  24.   3  if mod(i,5) = 0 then
  25.   4  update test_compress set id=id+i+40000,name=lpad('update',3000,'x') where id=i;
  26.   5  end if;
  27.   6  commit;
  28.   7  end loop;
  29.   8  end;
  30.   9  /
  31. PL/SQL procedure successfully completed.
  32.  
  33. SQL> analyze table test_compress estimate statistics;
  34. Table analyzed.
  35.  
  36. SQL> select  table_name,blocks,CHAIN_CNT  from dba_tables where table_name='TEST_COMPRESS';
  37. TABLE_NAME     BLOCKS     CHAIN_CNT
  38. ---------- -------------- ----------
  39. TEST_COMPRESS       1888      20673
  40.  
  41. SQL> select count(*) from TEST_COMPRESS;
  42.   COUNT(*)
  43. ----------
  44.      20000
  45.  
  46. SQL> alter table TEST_COMPRESS move;
  47. Table altered.
  48.  
  49. SQL> alter index BINZHANG.IDX2 rebuild;
  50. Index altered.
  51.  
  52. SQL> analyze table test_compress estimate statistics;
  53. Table analyzed.
  54.  
  55. SQL> select  table_name,blocks,CHAIN_CNT  from dba_tables where table_name='TEST_COMPRESS';
  56. TABLE_NAME     BLOCKS  CHAIN_CNT
  57. ---------- ---------- ----------
  58. TEST_COMPRESS         62          0

该功能的增强使得在CPU不是系统瓶颈的服务器上压缩不常用的相对不重要但要保留的历史纪录的时候多了一些灵活性。

more info see Oracle 11g Data Compression Tips for the Database Administrator

Del.icio.us Google书签 Digg Live Bookmark Technorati Furl Yahoo书签 Facebook 百度搜藏 新浪 ViVi 365Key 网摘 天极网摘 和讯网摘 博拉网 POCO 网摘 饭否 QQ 书签 Digbuzz 我挖网 Mister Wong
No comments yet.