Bo's Oracle Station

查看: 1525|回复: 0

BASIC压缩和ADVANCED压缩

[复制链接]

1005

主题

1469

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
12012
发表于 2020-10-27 21:59:10 | 显示全部楼层 |阅读模式
  1. create tablespace tbs_nocompression datafile size 10M autoextend on;

  2. create tablespace tbs_basic datafile size 10M autoextend on default compress basic;

  3. create tablespace tbs_oltp datafile size 10M autoextend on default compress for oltp;

  4. create tablespace tbs_query datafile size 10M autoextend on default compress for query;

  5. create tablespace tbs_archive datafile size 10M autoextend on default compress for archive;
  6. --sys-error--
  7. select  t.tablespace_name, t.def_tab_compression, t.compress_for  from dba_tablespaces t
  8. where t.tablespace_name in ('TBS_NOCOMPRESSION',
  9.                                                   'TBS_BASIC', 'TBS_OLTP',
  10.                                                    'TBS_QUERY',
  11.                                                    'TBS_ARCHIVE');
复制代码
  1. --hr--                                                   
  2. create table t_nocompression (a varchar2(200)) tablespace tbs_nocompression;
  3. create table t_basic (a varchar2(200)) tablespace tbs_basic;
  4. create table t_oltp (a varchar2(200)) tablespace tbs_oltp;
  5. --hr-error--
  6. create table t_query (a varchar2(200)) tablespace tbs_query;
  7. create table t_archive (a varchar2(200)) tablespace tbs_archive;
复制代码
  1. --hr--
  2. begin
  3.    for i in 1..400
  4.    loop
  5.       insert into t_nocompression values('AAAAAAAAAAAAAAAAAAAA');
  6.    end loop;
  7.    commit;
  8. end;
  9. --hr--
  10. begin
  11.    for i in 1..400
  12.    loop
  13.       insert into t_basic values('AAAAAAAAAAAAAAAAAAAA');
  14.    end loop;
  15.    commit;
  16. end;
  17. --hr--
  18. begin
  19.    for i in 1..400
  20.    loop
  21.       insert into t_oltp values('AAAAAAAAAAAAAAAAAAAA');
  22.    end loop;
  23.    commit;
  24. end;
复制代码
  1. --hr--
  2. select  t.TABLE_NAME, t.PCT_FREE , t.COMPRESSION , t.COMPRESS_FOR, t.TABLESPACE_NAME
  3. from user_tables t where t.TABLE_NAME   in ('T_NOCOMPRESSION','T_BASIC','T_OLTP');
复制代码

  1. --SYS--
  2. --sys--
  3. select   count(*)  ,    dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid)
  4.       from hr.T_NOCOMPRESSION  group by     dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid);
  5. --sys--
  6. select   count(*)  ,    dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC',row_id => rowid)
  7.       from hr.T_BASIC group by     dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC',row_id => rowid);
  8. --sys--      
  9. select   count(*)  ,    dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_OLTP',row_id => rowid)
  10.       from hr.T_OLTP group by     dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_OLTP',row_id => rowid);
复制代码
-------------------------------------------------------------------------------------------------------------
  1. <span class="y"><a href="https://www.botangdb.com/member.php?mod=logging&action=login&referer=https%3A%2F%2Fwww.botangdb.com%2Fforum.php%3Fmod%3Dviewthread%26tid%3D1474%26extra%3Dpage%253D1" class="xi2">现</a></span>--hr--
  2. create table t_basic2 (a varchar2(200)) tablespace tbs_nocompression compress;

  3. create table t_oltp2 (a varchar2(200)) tablespace tbs_nocompression row store compress advanced;
复制代码
  1. --hr-error--
  2. create table t_query2 (a varchar2(200)) tablespace tbs_nocompression compress for query;
  3. create table t_archive2 (a varchar2(200)) tablespace tbs_nocompression compress for archive;
复制代码
  1. --hr--
  2. select  t.TABLE_NAME, t.PCT_FREE , t.COM<span class="y"><a href="https://www.botangdb.com/member.php?mod=logging&action=login&referer=https%3A%2F%2Fwww.botangdb.com%2Fforum.php%3Fmod%3Dviewthread%26tid%3D1474%26extra%3Dpage%253D1" class="xi2">现</a></span>PRESSION , t.COMPRESS_FOR, t.TABLESPACE_NAME
  3. from user_tables t where t.TABLE_NAME   in ('T_NOCOMPRESSION','T_BASIC','T_OLTP',  'T_BASIC2','T_OLTP2' );
复制代码
T_OLTP2    10    ENABLED    ADVANCED    TBS_NOCOMPRESSION
T_OLTP    10    ENABLED    ADVANCED    TBS_OLTP
T_NOCOMPRESSION    10    DISABLED        TBS_NOCOMPRESSION
T_BASIC2    0    ENABLED    BASIC    TBS_NOCOMPRESSION
T_BASIC    0    ENABLED    BASIC    TBS_BASIC

  1. --hr--
  2. begin
  3.    for i in 1..400
  4.    loop
  5.       insert into t_basic2 values('AAAAAAAAAAAAAAAAAAAA');
  6.    end loop;
  7.    commit;
  8. end;
  9. --hr--
  10. begin
  11.    for i in 1..400
  12.    loop
  13.       insert into t_oltp2 values('AAAAAAAAAAAAAAAAAAAA');
  14.    end loop;
  15.    commit;
  16. end;
  17. --hr--
  18. select  count(*)  , substr(rowid, 10, 6 ) from hr.t_basic2  group by  substr(rowid, 10, 6 );
  19. select  count(*)  , substr(rowid, 10, 6 ) from hr.t_oltp2  group by  substr(rowid, 10, 6 );
  20. --sys--
  21. select   count(*)  ,    dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC2',row_id => rowid)
  22.       from hr.T_BASIC2 group by     dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC2',row_id => rowid);
  23. --sys--      
  24. select   count(*)  ,    dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_OLTP2',row_id => rowid)
  25.       from hr.T_OLTP2 group by     dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_OLTP2',row_id => rowid);
  26. --hr--
  27. alter table t_nocompression compress for oltp;
  28. select  t.TABLE_NAME, t.PCT_FREE , t.COMPRESSION , t.COMPRESS_FOR, t.TABLESPACE_NAME
  29. from user_tables t where t.TABLE_NAME   in ('T_NOCOMPRESSION','T_BASIC','T_OLTP',  'T_BASIC2','T_OLTP2' );
  30. select  count(*)  , substr(rowid, 10, 6 ) from hr.t_nocompression  group by  substr(rowid, 10, 6 );     
  31. --sys--
  32. select   count(*)  ,    dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid)
  33.    from hr.T_NOCOMPRESSION  group by     dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid);   
  34. --hr--
  35. begin
  36.    for i in 1..400
  37.    loop
  38.       insert into t_nocompression values('AAAAAAAAAAAAAAAAAAAA');
  39.    end loop;
  40.    commit;
  41. end;
  42. --hr--
  43. select  count(*)  , substr(rowid, 10, 6 ) from hr.t_nocompression  group by  substr(rowid, 10, 6 );
  44. --sys--
  45. select   count(*)  ,    dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid)
  46.       from hr.T_NOCOMPRESSION  group by     dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid);
  47. --hr--
  48. alter table t_nocompression move tablespace tbs_nocompression;
  49. select  count(*)  , substr(rowid, 10, 6 ) from hr.t_nocompression  group by  substr(rowid, 10, 6 );   
  50. --sys--
  51. select   count(*)  ,    dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid)
  52.       from hr.T_NOCOMPRESSION  group by     dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid);
  53. --hr--
  54. select  count(*)  , substr(rowid, 10, 6 ) from hr.t_basic  group by  substr(rowid, 10, 6 );  
  55. insert /*+ append */ into t_basic select  * from  t_basic;
  56. commit;
  57. select  count(*)  , substr(rowid, 10, 6 ) from hr.t_basic  group by  substr(rowid, 10, 6 );
  58. --sys--
  59. select   count(*)  ,    dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC',row_id => rowid)
  60.       from hr.T_BASIC group by     dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC',row_id => rowid);
  61. --hr--
  62. alter table t_basic move tablespace  TBS_NOCOMPRESSION;
  63. select  count(*)  , substr(rowid, 10, 6 ) from hr.t_basic  group by  substr(rowid, 10, 6 );      
  64. --sys--
  65. select   count(*)  ,    dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC',row_id => rowid)
  66.       from hr.T_BASIC group by     dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC',row_id => rowid);
  67. --sys-evolution--
  68. create table hr.tbig compress as select  * from dba_source;

  69. --sys-advisor--
  70. declare
  71.    v_blkcnt_cmp number;
  72.    v_blkcnt_uncmp  number;
  73.    v_row_cmp number;
  74.    v_row_uncmp number;
  75.    v_cmp_ratio number;
  76.    v_comptype_str  varchar2(200);
  77. BEGIN
  78.   DBMS_COMPRESSION.GET_COMPRESSION_RATIO( 'USERS',
  79.   'HR',
  80.   'TBIG',
  81.   null,
  82.   2,
  83.   v_blkcnt_cmp,
  84.   v_blkcnt_uncmp,
  85.   v_row_cmp,
  86.   v_row_uncmp,
  87.   v_cmp_ratio,
  88.   v_comptype_str);                                                  
  89.   DBMS_OUTPUT.PUT_LINE('Blk count compressed = ' || v_blkcnt_cmp);
  90. DBMS_OUTPUT.PUT_LINE('Blk count uncompressed = ' || v_blkcnt_uncmp);
  91. DBMS_OUTPUT.PUT_LINE('Row count per block compressed = ' || v_row_cmp);
  92. DBMS_OUTPUT.PUT_LINE('Row count per block uncompressed = ' || v_row_uncmp);
  93. DBMS_OUTPUT.PUT_LINE('ratio: '||v_cmp_ratio);
  94. DBMS_OUTPUT.PUT_LINE('Compression type = ' || v_comptype_str);
  95. end;
  96. --输出--
  97. Blk count compressed = 1785
  98. Blk count uncompressed = 2340
  99. Row count per block compressed = 68
  100. Row count per block uncompressed = 51
  101. ratio: 1.31092436974789915966386554621848739496
  102. Compression type = "Compress For OLTP"
  103. --OLTP压缩一下表--
  104. 验证表大小

  105. --sys--
  106. select   count(*)  ,    dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC_BIG',row_id => rowid)
  107.       from hr.T_BASIC_BIG group by     dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC_BIG',row_id => rowid);  
  108. --hr--
  109. create table t_basic_col( a  number , b varchar2(20))  compress ;
  110. insert into t_basic_col values ( 1,'A') ;
  111. commit;
  112. create table t_oltp_col( a  number , b varchar2(20))  compress  for oltp;
  113. insert into t_oltp_col values ( 1,'A') ;
  114. commit;
  115. select  * from  t_basic_col;
  116. select  * from t_oltp_col;
  117. alter table  t_basic_col drop column b;
  118. alter table  t_basic_col drop ( b);
  119. alter table t_oltp_col drop column b;
  120. select  * from t_oltp_col;
复制代码





回复

使用道具 举报

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

本版积分规则

QQ|手机版|Bo's Oracle Station   

GMT+8, 2024-11-21 23:57 , Processed in 0.045745 second(s), 25 queries .

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