Bo's Oracle Station

查看: 2396|回复: 0

第71/72/73/74次:2016-01-23/24双休日

[复制链接]

1005

主题

1469

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
12012
发表于 2016-1-27 10:33:14 | 显示全部楼层 |阅读模式
上完新特性1-5章
  1. Oracle11gR2的表压缩特性通过压缩表中的数据以减少对空间的占用。Oracle11gR2支持三种不同的压缩方式:
  2. ·        支持直接路径加载的Basic压缩方式(10x)
  3. ·        支持针对所有DML操作的OLTP压缩方式(2-4x)
  4. ·        Exadata专属的Hybrid columnar compression压缩方式

  5.     Oracle公司建议我们采用以上三种不同的压缩方式,针对特定的应用场合来进行表压缩。如果该表包含大量冗长的和重复的值,通过被压缩可以减少该表对磁盘空间的占用和对SGA中数据库缓冲区缓存的占用。
  6. 先从图形界面入手,我们发现在新建表空间时Oracle11gR2的界面出现压缩选项:
  7. 在 下面各个部分所有的实验中我们都创建两个表:一个表在TBS_NOCOMPRESSION表空间,另一个表在有对应默认压缩选项的表空间。最后我们把在 TBS_NOCOMPRESSION表空间上的那个表转换成对应压缩选项表。通过对比实验来弄清Oracle11gR2这方面的新特性。
  8. --sys--
  9. create tablespace tbs_nocompression datafile size 10M autoextend on;
  10. create tablespace tbs_basic datafile size 10M autoextend on default compress basic;
  11. create tablespace tbs_oltp datafile size 10M autoextend on default compress for oltp;
  12. create tablespace tbs_query datafile size 10M autoextend on default compress for query;
  13. create tablespace tbs_archive datafile size 10M autoextend on default compress for archive;
  14. select  t.tablespace_name, t.def_tab_compression, t.compress_for  from dba_tablespaces t
  15. where t.tablespace_name in ('TBS_NOCOMPRESSION',
  16.                                                   'TBS_BASIC', 'TBS_OLTP',
  17.                                                    'TBS_QUERY',
  18.                                                    'TBS_ARCHIVE');
  19. --hr--                                                   
  20. create table t_nocompression (a varchar2(200)) tablespace tbs_nocompression;
  21. create table t_basic (a varchar2(200)) tablespace tbs_basic;
  22. create table t_oltp (a varchar2(200)) tablespace tbs_oltp;
  23. --hr-error--
  24. create table t_query (a varchar2(200)) tablespace tbs_query;
  25. create table t_archive (a varchar2(200)) tablespace tbs_archive;  
  26. --hr--
  27. begin
  28.    for i in 1..400
  29.    loop
  30.       insert into t_nocompression values('AAAAAAAAAAAAAAAAAAAA');
  31.    end loop;
  32.    commit;
  33. end;
  34. --hr--
  35. begin
  36.    for i in 1..400
  37.    loop
  38.       insert into t_basic values('AAAAAAAAAAAAAAAAAAAA');
  39.    end loop;
  40.    commit;
  41. end;
  42. --hr--
  43. begin
  44.    for i in 1..400
  45.    loop
  46.       insert into t_oltp values('AAAAAAAAAAAAAAAAAAAA');
  47.    end loop;
  48.    commit;
  49. end;  
  50. --hr--
  51. select  t.TABLE_NAME, t.PCT_FREE , t.COMPRESSION , t.COMPRESS_FOR, t.TABLESPACE_NAME
  52. from user_tables t where t.TABLE_NAME   in ('T_NOCOMPRESSION','T_BASIC','T_OLTP');
  53. select  count(*)  , substr(rowid, 10, 6 ) from hr.t_nocompression  group by  substr(rowid, 10, 6 );
  54. select  count(*)  , substr(rowid, 10, 6 ) from hr.t_basic  group by  substr(rowid, 10, 6 );      
  55. select  count(*)  , substr(rowid, 10, 6 ) from hr.t_oltp  group by  substr(rowid, 10, 6 );  
  56. --sys--
  57. select   count(*)  ,    dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid)
  58.       from hr.T_NOCOMPRESSION  group by     dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid);
  59. --sys--
  60. select   count(*)  ,    dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC',row_id => rowid)
  61.       from hr.T_BASIC group by     dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC',row_id => rowid);
  62. --sys--      
  63. select   count(*)  ,    dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_OLTP',row_id => rowid)
  64.       from hr.T_OLTP group by     dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_OLTP',row_id => rowid);
  65. --hr--      
  66. create table t_basic2 (a varchar2(200)) tablespace tbs_nocompression compress;
  67. create table t_oltp2 (a varchar2(200)) tablespace tbs_nocompression compress for oltp;
  68. --hr-error--
  69. create table t_query2 (a varchar2(200)) tablespace tbs_nocompression compress for query;
  70. create table t_archive2 (a varchar2(200)) tablespace tbs_nocompression compress for archive;     
  71. --hr--
  72. select  t.TABLE_NAME, t.PCT_FREE , t.COMPRESSION , t.COMPRESS_FOR, t.TABLESPACE_NAME
  73. from user_tables t where t.TABLE_NAME   in ('T_NOCOMPRESSION','T_BASIC','T_OLTP',  'T_BASIC2','T_OLTP2' );
  74. --hr--
  75. begin
  76.    for i in 1..400
  77.    loop
  78.       insert into t_basic2 values('AAAAAAAAAAAAAAAAAAAA');
  79.    end loop;
  80.    commit;
  81. end;
  82. --hr--
  83. begin
  84.    for i in 1..400
  85.    loop
  86.       insert into t_oltp2 values('AAAAAAAAAAAAAAAAAAAA');
  87.    end loop;
  88.    commit;
  89. end;
  90. --hr--
  91. select  count(*)  , substr(rowid, 10, 6 ) from hr.t_basic2  group by  substr(rowid, 10, 6 );
  92. select  count(*)  , substr(rowid, 10, 6 ) from hr.t_oltp2  group by  substr(rowid, 10, 6 );
  93. --sys--
  94. select   count(*)  ,    dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC2',row_id => rowid)
  95.       from hr.T_BASIC2 group by     dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC2',row_id => rowid);
  96. --sys--      
  97. select   count(*)  ,    dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_OLTP2',row_id => rowid)
  98.       from hr.T_OLTP2 group by     dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_OLTP2',row_id => rowid);
  99. --hr--
  100. alter table t_nocompression compress for oltp;
  101. select  t.TABLE_NAME, t.PCT_FREE , t.COMPRESSION , t.COMPRESS_FOR, t.TABLESPACE_NAME
  102. from user_tables t where t.TABLE_NAME   in ('T_NOCOMPRESSION','T_BASIC','T_OLTP',  'T_BASIC2','T_OLTP2' );
  103. select  count(*)  , substr(rowid, 10, 6 ) from hr.t_nocompression  group by  substr(rowid, 10, 6 );     
  104. --sys--
  105. select   count(*)  ,    dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid)
  106.    from hr.T_NOCOMPRESSION  group by     dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid);   
  107. --hr--
  108. begin
  109.    for i in 1..400
  110.    loop
  111.       insert into t_nocompression values('AAAAAAAAAAAAAAAAAAAA');
  112.    end loop;
  113.    commit;
  114. end;
  115. --hr--
  116. select  count(*)  , substr(rowid, 10, 6 ) from hr.t_nocompression  group by  substr(rowid, 10, 6 );
  117. --sys--
  118. select   count(*)  ,    dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid)
  119.       from hr.T_NOCOMPRESSION  group by     dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid);
  120. --hr--
  121. alter table t_nocompression move tablespace tbs_nocompression;
  122. select  count(*)  , substr(rowid, 10, 6 ) from hr.t_nocompression  group by  substr(rowid, 10, 6 );   
  123. --sys--
  124. select   count(*)  ,    dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid)
  125.       from hr.T_NOCOMPRESSION  group by     dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid);
  126. --hr--
  127. select  count(*)  , substr(rowid, 10, 6 ) from hr.t_basic  group by  substr(rowid, 10, 6 );  
  128. insert /*+ append */ into t_basic select  * from  t_basic;
  129. commit;
  130. select  count(*)  , substr(rowid, 10, 6 ) from hr.t_basic  group by  substr(rowid, 10, 6 );
  131. --sys--
  132. select   count(*)  ,    dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC',row_id => rowid)
  133.       from hr.T_BASIC group by     dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC',row_id => rowid);
  134. --hr--
  135. alter table t_basic move tablespace  TBS_NOCOMPRESSION;
  136. select  count(*)  , substr(rowid, 10, 6 ) from hr.t_basic  group by  substr(rowid, 10, 6 );      
  137. --sys--
  138. select   count(*)  ,    dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC',row_id => rowid)
  139.       from hr.T_BASIC group by     dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC',row_id => rowid);
  140. --sys-evolution--
  141. drop table hr.t_basic_big;
  142. create table hr.t_basic_big compress as select  * from dba_source;
  143. --sys-advisor--
  144. declare
  145.   v_blkcnt_cmp number;
  146.   v_blkcnt_uncmp  number;
  147.   v_row_cmp number;
  148.   v_row_uncmp number;
  149.   v_cmp_ratio number;
  150.   v_comptype_str  varchar2(200);
  151. BEGIN
  152. DBMS_COMPRESSION.GET_COMPRESSION_RATIO(scratchtbsname => 'USERS',
  153.                                                                                              ownname =>'HR',
  154.                                                                                              tabname =>'T_BASIC_BIG',
  155.                                                                                              partname =>null,
  156.                                                                                              comptype => 2,
  157.                                                                                              blkcnt_cmp => v_blkcnt_cmp,
  158.                                                                                              blkcnt_uncmp =>  v_blkcnt_uncmp,
  159.                                                                                              row_cmp =>v_row_cmp,
  160.                                                                                              row_uncmp => v_row_uncmp,
  161.                                                                                              cmp_ratio =>  v_cmp_ratio,
  162.                                                                                              comptype_str =>v_comptype_str);                                                  
  163. DBMS_OUTPUT.PUT_LINE('Blk count compressed = ' || v_blkcnt_cmp);
  164. DBMS_OUTPUT.PUT_LINE('Blk count uncompressed = ' || v_blkcnt_uncmp);
  165. DBMS_OUTPUT.PUT_LINE('Row count per block compressed = ' || v_row_cmp);
  166. DBMS_OUTPUT.PUT_LINE('Row count per block uncompressed = ' || v_row_uncmp);
  167. DBMS_OUTPUT.PUT_LINE('ratio: '||v_cmp_ratio);
  168. DBMS_OUTPUT.PUT_LINE('Compression type = ' || v_comptype_str);
  169. end;
  170. --sys--
  171. select   count(*)  ,    dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC_BIG',row_id => rowid)
  172.       from hr.T_BASIC_BIG group by     dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC_BIG',row_id => rowid);  
  173. --hr--
  174. create table t_basic_col( a  number , b varchar2(20))  compress ;
  175. insert into t_basic_col values ( 1,'A') ;
  176. commit;
  177. create table t_oltp_col( a  number , b varchar2(20))  compress  for oltp;
  178. insert into t_oltp_col values ( 1,'A') ;
  179. commit;
  180. select  * from  t_basic_col;
  181. select  * from t_oltp_col;
  182. alter table  t_basic_col drop column b;
  183. alter table  t_basic_col drop ( b);
  184. alter table t_oltp_col drop column b;
  185. select  * from t_oltp_col;

复制代码



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|Bo's Oracle Station   

GMT+8, 2024-4-20 19:45 , Processed in 0.033933 second(s), 24 queries .

快速回复 返回顶部 返回列表