首页 > 其他分享 >表压缩

表压缩

时间:2022-09-27 22:24:43浏览次数:42  
标签:compression 压缩 COMPRESS TABLE STORE Compression

压缩可以节省磁盘空间,减少数据库缓冲区缓存中的内存使用,并且可以显着加快读取期间的查询执行速度。

压缩在数据加载和 DML 的 CPU 开销方面是有代价的。然而,这个成本被减少的 I/O 需求所抵消。由于压缩的表数据在内存中保持压缩状态,因此压缩还可以提高 DML 操作的性能,因为数据库缓冲区缓存(以及闪存缓存,如果启用)可以容纳更多行。

表压缩对应用程序完全透明。它在决策支持系统 (DSS)、在线事务处理 (OLTP) 系统和档案系统中很有用。

您可以为表空间、表或分区指定压缩。如果在表空间级别指定,则默认压缩在该表空间中创建的所有表。

Table Compression Methods

Table Compression MethodCompression LevelCPU OverheadApplicationsNotes

Basic table compression

High

Minimal

DSS

None.

Advanced row compression

High

Minimal

OLTP, DSS

None.

Warehouse compression (Hybrid Columnar Compression)

Higher

Higher

DSS

The compression level and CPU overhead depend on compression level specified (LOW or HIGH).

Archive compression (Hybrid Columnar Compression)

Highest

Highest

Archiving

The compression level and CPU overhead depend on compression level specified (LOW or HIGH).

当您使用基本表压缩、仓库压缩或存档压缩时,压缩仅在数据被批量加载或数组插入到表中时发生。

基本表压缩支持有限的数据类型和 SQL 操作。

高级行压缩适用于 OLTP 应用程序并压缩由任何 SQL 操作操作的数据。当您使用高级行压缩时,在将数据插入、更新或批量加载到表中时会发生压缩。允许高级行压缩的操作包括:

  • 单行插入和更新

    插入和更新不会立即压缩。更新已压缩的块时,任何未更新的列通常保持压缩状态。更新的列以类似于任何未压缩块的未压缩格式存储。当块达到数据库控制的阈值时,将重新压缩更新的值。当块中的数据达到数据库控制的阈值时,插入的数据也会被压缩。

  • Array inserts

    Array inserts include INSERT INTO SELECT SQL statements without the APPEND hint, and array inserts from programmatic interfaces such as PL/SQL and the Oracle Call Interface (OCI).

The following direct-path INSERT methods:

  • Direct path SQL*Loader

  • CREATETABLEASSELECT statements

  • Parallel INSERT statements

  • INSERT statements with an APPEND or APPEND_VALUES hint

Inserts performed with these direct-path INSERT methods are compressed immediately.

 

无论采用何种压缩方法,压缩块上的DELETE操作都与非压缩块的DELETE操作相同。SQL DELETE操作在数据块上获得的任何空间都将被后续的SQL INSERT操作重用。使用混合柱状压缩技术,当压缩单元中的所有行都被删除时,压缩单元内的空间可供重用。

表压缩特性

Table Compression MethodCREATE/ALTER TABLE SyntaxDirect-Path or Array InsertsNotes

Basic table compression

ROW STORE COMPRESS [BASIC]

Rows are compressed with basic table compression.

ROW STORE COMPRESS and ROW STORE COMPRESS BASIC are equivalent.

Rows inserted without using direct-path or array insert and updated rows are uncompressed.

Advanced row compression

ROW STORE COMPRESS ADVANCED

Rows are compressed with advanced row compression.

Rows inserted with or without using direct-path or array insert and updated rows are compressed using advanced row compression.

Warehouse compression (Hybrid Columnar Compression)

COLUMN STORE COMPRESS FOR QUERY [LOW|HIGH]

Rows are compressed with warehouse compression.

This compression method can result in high CPU overhead.

Updated rows and rows inserted without using direct-path or array insert are stored in row format instead of column format, and thus have a lower compression level.

Archive compression (Hybrid Columnar Compression)

COLUMN STORE COMPRESS FOR ARCHIVE [LOW|HIGH]

Rows are compressed with archive compression.

This compression method can result in high CPU overhead.

Updated rows and rows inserted without using direct-path or array insert are stored in row format instead of column format, and thus have a lower compression level.

使用CREATE table语句的COMPRESS子句指定表压缩。通过在ALTER table语句中使用这些子句,可以对现有表启用压缩。在这种情况下,仅压缩启用压缩后插入或更新的数据。使用ALTER TABLE MOVE语句还可以对插入和更新的数据进行压缩,但它也会压缩现有数据。类似地,可以使用ALTER table…NOCOMPRESS语句禁用现有压缩表的表压缩。在这种情况下,所有已经压缩的数据都将保持压缩状态,新数据将在未压缩的情况下插入。

COLUMN STORE COMPRESS FOR QUERY HIGH选项是默认的数据仓库压缩模式。在Exadata存储上使用混合列压缩时,它提供了良好的压缩和性能。在负载性能至关重要的环境中,应使用COLUMN STORE COMPRESS FOR QUERY LOW选项。它的加载速度比使用COLUMN STORE COMPRESS FOR QUERY HIGH选项压缩的数据快。

COLUMN STORE COMPRESS FOR ARCHIVE LOW选项是默认的存档压缩模式。它提供了高压缩级别,非常适合于不常访问的数据。对于很少访问的数据,应使用COLUMN STORE COMPRESS FOR ARCHIVE HIGH选项。

DBMS_compression包提供的压缩顾问可以帮助您确定具有特定压缩方法的特定表的预期压缩级别。

Example 

Creating a Table with Advanced Row Compression

The following example enables advanced row compression on the table orders:

CREATE TABLE orders ... ROW STORE COMPRESS ADVANCED;

订单表的数据在直接路径INSERT、数组插入和常规DML期间被压缩。

Creating a Table with Basic Table Compression

以下语句是等效的,可以对sales_history表(数据仓库中的事实表)启用基本表压缩:

CREATE TABLE sales_history  ...  ROW STORE COMPRESS BASIC;

CREATE TABLE sales_history  ...  ROW STORE COMPRESS;

经常对该表运行查询,但不需要DML。

Using Direct-Path Insert to Insert Rows Into a Table

此示例演示了使用APPEND提示,使用直接路径insert将行插入sales_history表。

INSERT /*+ APPEND */ INTO sales_history SELECT * FROM sales WHERE cust_id=8890;
COMMIT;

Using an Array Insert to Insert Rows Into a Table

他的示例演示了在SQL中使用数组插入将行插入sales_history表。

INSERT INTO sales_history SELECT * FROM sales WHERE cust_id=8890;
COMMIT;

此示例演示如何在PL/SQL中使用数组插入将行插入hr.jobs_test表。

DECLARE
   TYPE table_def IS TABLE OF hr.jobs%ROWTYPE;
   array table_def := table_def();
BEGIN
   SELECT * BULK COLLECT INTO array FROM hr.jobs;
   FORALL i in array.first .. array.last
   INSERT INTO hr.jobs_test VALUES array(i);
COMMIT;
END; 
/

 

注意:使用混合列压缩(仓库和归档),对于要立即压缩的SQL、PL/SQL或OCI中执行的数组插入,表必须存储在启用自动段空间管理(ASSM)的本地管理表空间中,并且数据库兼容级别必须为12.2.0或更高。

 

Creating a Table with Warehouse Compression使用仓库压缩创建表

此示例在表sales_history上启用混合列压缩:

CREATE TABLE sales_history  ...  COLUMN STORE COMPRESS FOR QUERY;

该表是使用默认的COLUMN STORE COMPRESS FOR QUERY HIGH选项创建的。此选项提供比基本表压缩或高级行压缩更高级别的压缩。当对该表运行频繁的查询并且不需要DML时,它工作得很好。

 

Creating a Table with Archive Compression使用存档压缩创建表

以下示例在表sales_history上启用混合列压缩:

CREATE TABLE sales_history  ...  COLUMN STORE COMPRESS FOR ARCHIVE;

使用默认的COLUMN STORE COMPRESS FOR ARCHIVE LOW选项创建表格。此选项提供比基本、高级行或仓库压缩更高级别的压缩。当负载性能非常关键且数据访问不频繁时,它可以很好地工作。默认的“COLUMN STORE COMPRESS FOR ARCHIVE LOW”选项提供的压缩级别低于“COLUM STORE CONPRESS of ARCHIVE HIGH”选项。

Compression and Partitioned Tables

一个表可以有压缩分区和未压缩分区,不同的分区可以使用不同的压缩方法。如果表及其某个分区的压缩设置不匹配,则分区设置优先于该分区。

要更改分区的压缩方法,请执行以下操作之一:

  • 要仅更改新数据的压缩方法,请使用ALTER TABLE…MODIFY PARTITION…COMPRESS。。。
  • 要更改新数据和现有数据的压缩方法,请使用ALTER TABLE…MOVE PARTITION…COMPRESS…或联机表重新定义。

执行这些语句时,请指定压缩方法。例如,运行以下语句将新数据和现有数据的压缩方法更改为高级行压缩:

ALTER TABLE ... MOVE PARTITION ... ROW STORE COMPRESS ADVANCED...

 

确定表是否已压缩

In the *_TABLES data dictionary views, compressed tables have ENABLED in the COMPRESSION column.

对于分区表,此列为空,*_TAB_PARTITIONS视图的COMPRESSION列指示压缩的分区。此外,COMPRESS_FOR列指示表或分区使用的压缩方法。

SQL> SELECT table_name, compression, compress_for FROM user_tables;
 
TABLE_NAME       COMPRESSION   COMPRESS_FOR
---------------- ------------  -----------------
T1               DISABLED
T2               ENABLED       BASIC
T3               ENABLED       ADVANCED
T4               ENABLED       QUERY HIGH
T5               ENABLED       ARCHIVE LOW
SQL> SELECT table_name, partition_name, compression, compress_for
  FROM user_tab_partitions;

TABLE_NAME  PARTITION_NAME   COMPRESSION   COMPRESS_FOR
----------- ---------------- -----------   ------------------------------
SALES       Q4_2004          ENABLED       ARCHIVE HIGH
  ...
SALES       Q3_2008          ENABLED       QUERY HIGH
SALES       Q4_2008          ENABLED       QUERY HIGH
SALES       Q1_2009          ENABLED       ADVANCED
SALES       Q2_2009          ENABLED       ADVANCED
Determining Which Rows Are Compressed确定压缩哪些行

要确定行的压缩级别,请使用DBMS_compression包中的GET_compression_TYPE函数。

 例如,以下查询返回hr.employees表中某行的压缩类型:

SELECT DECODE(DBMS_COMPRESSION.GET_COMPRESSION_TYPE(
                 ownname    => 'HR', 
                 tabname    => 'EMPLOYEES', 
                 subobjname => '',
                 row_id     => 'AAAVEIAAGAAAABTAAD'), 
   1,  'No Compression',
   2,  'Advanced Row Compression', 
   4,  'Hybrid Columnar Compression for Query High',
   8,  'Hybrid Columnar Compression for Query Low',
   16, 'Hybrid Columnar Compression for Archive High',
   32, 'Hybrid Columnar Compression for Archive Low',
   4096, 'Basic Table Compression', 
   'Unknown Compression Type') compression_type
FROM DUAL;

 

待续、、、、、、、

 

 

 

 

 

 

标签:compression,压缩,COMPRESS,TABLE,STORE,Compression
From: https://www.cnblogs.com/wonchaofan/p/16736222.html

相关文章

  • Linux命令查找和压缩 find which whereis 和tar
    1 find的命令1.1命令的特点:精确查找实时查找支持查找条件很多各表达式之间使用逻辑运算符,“-a”表示而且(and),“-o”表示或者(or)  查找路径:指定具体目标路......
  • Webpack之抽离压缩css
    使用 mini-css-extract-plugin插件的内置loader替换style-loader使用 terser-webpack-plugin插件压缩js代码使用 optimize-css-assets-webpack-plugin插件压缩cs......
  • 数据压缩、解压
    应用实例代码实现publicclassHuffmanCode{ publicstaticvoidmain(String[]args){ Stringcontent="ilikelikelikejavadoyoulikeajava"; ......
  • C++源码压缩程序
    C++源码压缩程序一、必做内容:(一)压缩器1.为了提高C++源程序的可读性,C++程序在书写过程中加入了空行、空格、缩进、注释等。假设你想牺牲可读性,以节省磁盘空间,那么你可以......
  • mozjpeg进行压缩时失败
    参考链接:npm安装包时报错[email protected]半亩方塘(bluepost.cn)(1条消息)mozjpeg安装失败/Failedatthemozjpeg_imH......
  • 基于扩散模型的图像压缩:创建基于Stable Diffusion的有损压缩编解码器
    StableDiffusion是最近在图像生成领域大火的模型,在对他研究的时候我发现它可以作为非常强大的有损图像压缩编解码器。在介绍之前,我们先看看它与高压缩率下的JPG和WebP相比......
  • Linux查看文件内容和压缩文件命令
    查看文件内容一些重要的目录:/usr/share/    帮助文档、说明文档/var/log/      日志/var/run/      运行中程序/var/tmp      临时文件根(/......
  • Hive压缩和存储
    1.压缩(1)Hive支持的压缩编码压缩格式工具算法文件扩展名是否可切分对应的编码/解码器DEFLATE无DEFLATE.deflate否org.apache.hado......
  • java 从oss上下载多个图片,压缩并返回给前端下载
    controller层/***下载图片-->创建文件夹*@paramparams*@return*@throwsException*/@PostMapping("/handerImageDownload")......
  • sentry 压缩文件后上报的实践
    项目中在使用sentry上传事件的attachment函数过程中发现,附带的log文件是未压缩的,于是有了需求,即需要在sentry内部将未压缩的文件流压缩后再上传给服务器这个需求......