oracle表压缩技术(BAISC vs OLTP)_orcale 表 压缩 原理-程序员宅基地

技术标签: oracle  

  from:http://blog.csdn.net/pioayang/article/details/23758695

oracle压缩技术分为基本表压缩(basic table compression),OLTP表压缩(OLTP table compression),索引压缩(index compression)和混合列压缩(hybrid columnar compression (HCC)

basic compression从9i开始推出,是oracle的默认压缩方式。OLTP compression是11g开始推出,支持所有类型的DML操作的数据压缩。压缩会节省磁盘空间,但可能会增加CPU资源的消耗。本文主要讨论常用的basic和LTOP压缩,索引压缩和HCC可以参考oracle其它文档。表压缩技术适合OLAP系统和OLTP系统中数据变化很小的历史表,不适合频繁DML操作的表

 

1.1    压缩的原理

以OLTP压缩为例,引用参考文档4的说明,原理如下

请看一个 ACCOUNTS 表,它包含以下记录:


在数据库内部,假定一个数据库块包含上述所有行。


解压缩的块看上去是这样的:记录中的所有字段(列)都包含数据。压缩此块时,数据库首先计算在所有行中发现的重复值,将这些值移出行外,然后将其放在块的头部附近。行中的这些重复值将被替换为一个表示其中每个值的符号。从概念上讲,它看上去如下图所示,您可以看到压缩前后的块。


注意这些值是如何从行中取出并放入顶部称为“符号表”的特殊区域中的。列中的每个值都被分配一个符号,此符号将替代行内的实际值。由于符号所占空间小于实际值,因此记录大小也远远小于初始值。行中的重复数据越多,符号表和块越紧凑。

由于压缩作为触发事件发生,而不是在插入行时发生,因此在正常的 DML 进程中压缩对性能没有任何影响。压缩被触发后,对 CPU 的需求肯定会变得很高,但在其他任何时间 CPU 影响都为零,因此压缩也适用于 OLTP 应用程序,这是 Oracle Database 11g 中压缩的平衡点。

除了减少空间占用外,压缩数据还将缩短网络传输时间、减少备份空间,并使在 QA 和测试中维护生产数据库的完整副本变得切实可行。

1.2    basic压缩

下面通过具体的实验来看basic压缩和OLTP压缩的效果和异同点。

basic compression的6组实验,来比较各种情况下的表压缩

 

[sql]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. sys@MS4ADB3(dtydb5)> select count(*)from test;  
  2.  COUNT(*)  
  3.   
  4. ----------  
  5.   
  6.     50000  
  7.   
  8. --       1.Baseline CTAS  
  9.   
  10. create table t1 tablespace users  
  11. as  
  12. select * from test where rownum <=50000;  
  13.   
  14. --       2.CTAS with basic compression enabled  
  15.   
  16. create table t2 compress basic tablespaceusers  
  17. as  
  18. select * from test where rownum <=50000;  
  19.   
  20. --       3.Normal insert into empty table defined as compressed  
  21.   
  22. create table t3 compress basic tablespaceusers  
  23. as  
  24. select * from test where rownum = 0;  
  25. insert into t3 select * from test whererownum <= 50000;  
  26.   
  27. --       4.Direct path insert into empty table defined as compressed  
  28.   
  29. create table t4 compress basic tablespaceusers  
  30. as  
  31. select * from test where rownum = 0;  
  32.   
  33. insert /*+append*/ into t4 select * fromtest where rownum <= 50000  
  34.   
  35. --       5.CTAS without compression, then change to compressed  
  36.   
  37. create table t5 tablespace users  
  38. as  
  39. select * from test where rownum <=50000;  
  40.   
  41. alter table t5 compress basic;   
 
[sql]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. --- 6. table move compress  
  2.   
  3. create table t6 tablespace users  
  4. as  
  5. select * from test where rownum <=50000;  
  6. alter table t6 move compress basic;  
对表做表分析

  

[sql]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. execdbms_stats.gather_table_stats('SYS','T1');  
  2.   
  3. execdbms_stats.gather_table_stats('SYS','T2');  
  4.   
  5. execdbms_stats.gather_table_stats('SYS','T3');  
  6.   
  7. execdbms_stats.gather_table_stats('SYS','T4');  
  8.   
  9. execdbms_stats.gather_table_stats('SYS','T5');  
  10.   
  11. execdbms_stats.gather_table_stats('SYS','T6');  
  12.   
  13.    
查询表占用空间情况

[sql]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. sys@MS4ADB3(dtydb5)> select  table_name,blocks, pct_free , compression,compress_for  
  2.  2      from    user_tables  
  3.  3      where   table_name in('T1','T2','T3','T4','T5','T6');  
  4.   
  5.    
  6. TABLE_NAME                                                      BLOCKS   PCT_FREE COMPRESSION      COMPRESS_FOR  
  7.   
  8. ---------------------------------------------------------------------- ---------- ---------------- ------------------------  
  9. T1                                                                 666         10 DISABLED  
  10. T2                                                                 204          0 ENABLED          BASIC  
  11. T3                                                                 622          0 ENABLED          BASIC  
  12. T4                                                                 204          0 ENABLED          BASIC  
  13. T5                                                                  666         10 ENABLED          BASIC  
  14. T6                                                                 204          0 ENABLED          BASIC  
  15.   
  16.    
  17.   
  18. sys@MS4ADB3(dtydb5)> selectsegment_name,bytes/1024 K from dba_segments where segment_name in('T1','T2','T3','T4','T5','T6');  
  19.   
  20. SEGMENT_NA          K  
  21.   
  22. --------- ----------  
  23. T1               6144  
  24. T2               2048  
  25. T3               5120  
  26. T4               2048  
  27. T5               6144  
  28. T6               2048  
 

结果分析:

从上可以看出,

basic compression

在CATS,insert /*+append*/和move compress操作会对数据进行压缩。而alter table compress操作会修改表的压缩属性,但不会对已有数据进行压缩,对压缩表做普通的insert操作也不对对数据进行压缩。压缩表的PCT_FREE为0,说明oracle设计基本压缩表的目的就是认为此类表以后会很少修改

 

 

 

1.3    OLTP压缩

使用OLTP压缩分别做以下6组实验

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. --    1. Baseline CTAS  
  2. create table t21 tablespace users  
  3. as  
  4. select * from test where rownum <= 50000;  
  5.   
  6. --    2. CTAS with  OLTP compress enabled  
  7. create table t22 compress for OLTP tablespace users  
  8. as  
  9. select * from test where rownum <= 50000;  
  10.   
  11. --    3. Normal insert into empty table defined as compressed  
  12. create table t23 compress for OLTP tablespace users  
  13. as  
  14. select * from test where rownum = 0;  
  15.   
  16. insert into t23 select * from test where rownum <= 50000;  
  17.   
  18. --    4. Direct path insert into empty table defined as compressed  
  19. create table t24 compress for OLTP tablespace users  
  20. as  
  21. select * from test where rownum = 0;  
  22.   
  23. insert /*+append*/ into t24 select * from test where rownum <= 50000;  
  24.   
  25. --    5. CTAS without compression, then change to compressed  
  26. create table t25 tablespace users  
  27. as  
  28. select * from test where rownum <= 50000;  
  29.   
  30. alter table t25 compress for OLTP;   
  31.   
  32. --- 6. table move compress  
  33. create table t26 tablespace users  
  34. as  
  35. select * from test where rownum <= 50000;  
  36. alter table t26 move compress for OLTP;  
表分析

 

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. exec dbms_stats.gather_table_stats('SYS','T21');  
  2. exec dbms_stats.gather_table_stats('SYS','T22');  
  3. exec dbms_stats.gather_table_stats('SYS','T23');  
  4. exec dbms_stats.gather_table_stats('SYS','T24');  
  5. exec dbms_stats.gather_table_stats('SYS','T25');  
  6. exec dbms_stats.gather_table_stats('SYS','T26');   

表占用空间的大小

[sql]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. sys@MS4ADB3(dtydb5)> select  table_name,blocks, pct_free , compression, compress_for  
  2.   2      from    user_tables  
  3.   3      where   table_name in ('T21','T22','T23','T24','T25','T26');  
  4.   
  5. TABLE_NAME                                                       BLOCKS   PCT_FREE COMPRESSION      COMPRESS_FOR  
  6. ------------------------------------------------------------ ---------- ---------- ---------------- ------------------------  
  7. T21                                                                 666         10 DISABLED  
  8. T22                                                                 225         10 ENABLED          OLTP  
  9. T23                                                                 370         10 ENABLED          OLTP  
  10. T24                                                                 225         10 ENABLED          OLTP  
  11. T25                                                                 666         10 ENABLED          OLTP  
  12. T26                                                                 225         10 ENABLED          OLTP  

比较分析
OTLP压缩实现了对DML操作的压缩(T23表),主要原理如图所示,当向空块插入数据时,数据不压缩,只有当数据超过一个阀值时,此时oracle才对数据块进行压缩,而且可能对同一个数据块多次压缩


转化为压缩表的3方法

1. ALTER TABLE … COMPRESS FOR OLTP
此方法对现有数据不压缩,对以后的DML语句相关数据进行OLTP压缩

2. Online Redefinition (DBMS_REDEFINITION)
对现有和以后的数据均压缩。使用DBMS_REDEFINITION可以在线对表进行操作,可以使用并行操作。分区表的global index是个例外,需要在线重定义之后重建索引

3. ALTER TABLE … MOVE COMPRESS FOR OLTP
对现有和以后的数据均压缩。在move过程中,会对表加排它(X)锁,DML操作会被阻塞,可以使用并行提高性能。move操作会导致索引失效,因此move之后需要重建索引。move操作可以改变segment的表空间



 参考文档
http://blog.csdn.net/tianlesoftware/article/details/8170488
http://allthingsoracle.com/compression-oracle-basic-table-compression/
Advanced Compression with Oracle Database 11g
http://www.oracle.com/technetwork/cn/articles/oem/11g-compression-198295-zhs.html

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/pioayang/article/details/23947717

智能推荐

while循环&CPU占用率高问题深入分析与解决方案_main函数使用while(1)循环cpu占用99-程序员宅基地

文章浏览阅读3.8k次,点赞9次,收藏28次。直接上一个工作中碰到的问题,另外一个系统开启多线程调用我这边的接口,然后我这边会开启多线程批量查询第三方接口并且返回给调用方。使用的是两三年前别人遗留下来的方法,放到线上后发现确实是可以正常取到结果,但是一旦调用,CPU占用就直接100%(部署环境是win server服务器)。因此查看了下相关的老代码并使用JProfiler查看发现是在某个while循环的时候有问题。具体项目代码就不贴了,类似于下面这段代码。​​​​​​while(flag) {//your code;}这里的flag._main函数使用while(1)循环cpu占用99

【无标题】jetbrains idea shift f6不生效_idea shift +f6快捷键不生效-程序员宅基地

文章浏览阅读347次。idea shift f6 快捷键无效_idea shift +f6快捷键不生效

node.js学习笔记之Node中的核心模块_node模块中有很多核心模块,以下不属于核心模块,使用时需下载的是-程序员宅基地

文章浏览阅读135次。Ecmacript 中没有DOM 和 BOM核心模块Node为JavaScript提供了很多服务器级别,这些API绝大多数都被包装到了一个具名和核心模块中了,例如文件操作的 fs 核心模块 ,http服务构建的http 模块 path 路径操作模块 os 操作系统信息模块// 用来获取机器信息的var os = require('os')// 用来操作路径的var path = require('path')// 获取当前机器的 CPU 信息console.log(os.cpus._node模块中有很多核心模块,以下不属于核心模块,使用时需下载的是

数学建模【SPSS 下载-安装、方差分析与回归分析的SPSS实现(软件概述、方差分析、回归分析)】_化工数学模型数据回归软件-程序员宅基地

文章浏览阅读10w+次,点赞435次,收藏3.4k次。SPSS 22 下载安装过程7.6 方差分析与回归分析的SPSS实现7.6.1 SPSS软件概述1 SPSS版本与安装2 SPSS界面3 SPSS特点4 SPSS数据7.6.2 SPSS与方差分析1 单因素方差分析2 双因素方差分析7.6.3 SPSS与回归分析SPSS回归分析过程牙膏价格问题的回归分析_化工数学模型数据回归软件

利用hutool实现邮件发送功能_hutool发送邮件-程序员宅基地

文章浏览阅读7.5k次。如何利用hutool工具包实现邮件发送功能呢?1、首先引入hutool依赖<dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>5.7.19</version></dependency>2、编写邮件发送工具类package com.pc.c..._hutool发送邮件

docker安装elasticsearch,elasticsearch-head,kibana,ik分词器_docker安装kibana连接elasticsearch并且elasticsearch有密码-程序员宅基地

文章浏览阅读867次,点赞2次,收藏2次。docker安装elasticsearch,elasticsearch-head,kibana,ik分词器安装方式基本有两种,一种是pull的方式,一种是Dockerfile的方式,由于pull的方式pull下来后还需配置许多东西且不便于复用,个人比较喜欢使用Dockerfile的方式所有docker支持的镜像基本都在https://hub.docker.com/docker的官网上能找到合..._docker安装kibana连接elasticsearch并且elasticsearch有密码

随便推点

Python 攻克移动开发失败!_beeware-程序员宅基地

文章浏览阅读1.3w次,点赞57次,收藏92次。整理 | 郑丽媛出品 | CSDN(ID:CSDNnews)近年来,随着机器学习的兴起,有一门编程语言逐渐变得火热——Python。得益于其针对机器学习提供了大量开源框架和第三方模块,内置..._beeware

Swift4.0_Timer 的基本使用_swift timer 暂停-程序员宅基地

文章浏览阅读7.9k次。//// ViewController.swift// Day_10_Timer//// Created by dongqiangfei on 2018/10/15.// Copyright 2018年 飞飞. All rights reserved.//import UIKitclass ViewController: UIViewController { ..._swift timer 暂停

元素三大等待-程序员宅基地

文章浏览阅读986次,点赞2次,收藏2次。1.硬性等待让当前线程暂停执行,应用场景:代码执行速度太快了,但是UI元素没有立马加载出来,造成两者不同步,这时候就可以让代码等待一下,再去执行找元素的动作线程休眠,强制等待 Thread.sleep(long mills)package com.example.demo;import org.junit.jupiter.api.Test;import org.openqa.selenium.By;import org.openqa.selenium.firefox.Firefox.._元素三大等待

Java软件工程师职位分析_java岗位分析-程序员宅基地

文章浏览阅读3k次,点赞4次,收藏14次。Java软件工程师职位分析_java岗位分析

Java:Unreachable code的解决方法_java unreachable code-程序员宅基地

文章浏览阅读2k次。Java:Unreachable code的解决方法_java unreachable code

标签data-*自定义属性值和根据data属性值查找对应标签_如何根据data-*属性获取对应的标签对象-程序员宅基地

文章浏览阅读1w次。1、html中设置标签data-*的值 标题 11111 222222、点击获取当前标签的data-url的值$('dd').on('click', function() { var urlVal = $(this).data('ur_如何根据data-*属性获取对应的标签对象

推荐文章

热门文章

相关标签