46 DBMS_COMPRESSION
DBMS_COMPRESSION
パッケージは、アプリケーションの正しい圧縮レベルを簡単に選択できるインタフェースを提供します。
この章のトピックは、次のとおりです:
46.1 DBMS_COMPRESSIONの概要
DBMS_COMPRESSION
パッケージは、データベース環境内で圧縮に関連する情報を収集します。これには、パーティション化された表およびパーティション化されていない表について圧縮率を推測し、以前に圧縮された表に関する行レベルの圧縮情報を収集するツールが含まれます。これによって、圧縮に関連した決定を行うための適切な情報が得られます。
46.2 DBMS_COMPRESSIONのセキュリティ・モデル
DBMS_COMPRESSSION
パッケージはAUTHID CURRENT USER
で定義されるため、現在のユーザーの権限で実行されます。
46.3 DBMS_COMPRESSIONの定数
DBMS_COMPRESSION
パッケージでは、パラメータ値の指定に使用できる定数が使用されます。
これらの定数を、次の表に示します。
表46-1 DBMS_COMPRESSIONの定数 - 圧縮タイプ
定数 | タイプ | 値 | 説明 |
---|---|---|---|
|
|
|
圧縮なし |
|
|
|
高度な行圧縮 |
|
|
|
問合せ用の高ウェアハウス圧縮(ハイブリッド列圧縮) |
|
|
|
問合せ用の低ウェアハウス圧縮(ハイブリッド列圧縮) |
|
|
|
高アーカイブ圧縮(ハイブリッド列圧縮) |
|
|
|
低アーカイブ圧縮(ハイブリッド列圧縮) |
|
|
|
圧縮ブロック |
|
|
|
LOB操作のための高圧縮レベル |
|
|
|
LOB操作のための中圧縮レベル |
|
|
|
LOB操作のための低圧縮レベル |
|
|
|
索引のための高圧縮レベル |
|
|
|
索引のための低圧縮レベル |
|
|
|
LOB圧縮率が見積られるオブジェクトの必要最低限のLOB数 |
|
|
|
基本表圧縮 |
|
|
|
LOB圧縮率の計算に使用されるLOBの最大数 |
|
|
|
インメモリー圧縮なし |
|
|
|
DMLのためのインメモリー圧縮レベル |
|
|
|
問合せパフォーマンスのために最適化されたインメモリー圧縮レベル |
|
|
|
問合せパフォーマンスおよび領域の節約に対して最適化されたインメモリー圧縮レベル |
|
|
|
容量を最適化するインメモリー低圧縮レベル |
|
|
|
容量を最適化するインメモリー高圧縮レベル |
|
|
|
HCC比が見積もられるオブジェクトの必要最低限の行数 |
|
|
|
オブジェクトのすべての行を使用してHCC比が見積もられたことを示します。 |
|
|
|
圧縮率を見積もるオブジェクトをタイプ表として識別します。 |
|
|
2 |
圧縮率が見積もられるオブジェクトをタイプ索引として識別します。 |
ノート:
ハイブリッド列圧縮は特定のOracleストレージ・システムの機能です。詳細は、『Oracle Database概要』を参照してください。
46.4 DBMS_COMPRESSIONのデータ構造
46.4.1 COMPRECレコード・タイプ
COMPRECレコード・タイプは、表の個々の索引圧縮率を計算するためのレコードです。
構文
TYPE COMPREC IS RECORD( ownname varchar2(255), objname varchar2(255), blkcnt_cmp PLS_INTEGER, blkcnt_uncmp PLS_INTEGER, row_cmp PLS_INTEGER, row_uncmp PLS_INTEGER, cmp_ratio NUMBER, objtype PLS_INTEGER);
フィールド
表46-2 COMPRECの属性
フィールド | 説明 |
---|---|
|
オブジェクト所有者のスキーマ。 |
|
オブジェクト名 |
|
オブジェクトの圧縮されたサンプルに使用されるブロック数。 |
|
オブジェクトの圧縮解除されたサンプルに使用されるブロック数。 |
|
オブジェクトの圧縮されたサンプルにあるブロック内の行数。 |
|
オブジェクトの圧縮解除されたサンプルにあるブロック内の行数。 |
|
圧縮比、 |
|
オブジェクトのタイプ |
46.5 DBMS_COMPRESSIONサブプログラムの要約
DBMS_COMPRESSION
パッケージでは、GET_COMPRESSION_RATIO
プロシージャおよびGET_COMPRESSION_TYPE
ファンクションのサブプログラムが使用されます。
表46-3 DBMS_COMPRESSIONパッケージのサブプログラム
サブプログラム | 説明 |
---|---|
表の圧縮比を分析し、表の圧縮率に関する情報を提供します。 |
|
特定の行に対する圧縮タイプを戻します。 |
46.5.1 GET_COMPRESSION_RATIOプロシージャ
このプロシージャを使用して、表または索引の圧縮比を分析し、オブジェクトの圧縮率に関する情報を得ます。各種のパラメータを指定して、個別の圧縮タイプを選択的に分析できます。
Oracle Database 23cでは、このプロシージャが拡張されていて、少ない領域の使用でLOBの圧縮率をより速く推定するようになりました。BasicFile LOBの圧縮率の推定も可能になりました。これにより、BasicFile LOBのSecureFile LOBへの移行前に、BasicFile LOBを圧縮するかどうかを事前に決定できます。さらに、LOBバイト・レベルでの圧縮比の推定や、表内のLOBデータの圧縮にかかる時間の推定もできます(時間単位)。
構文
圧縮率を取得するための構文は、オブジェクト、LOB、IOTおよび表の索引に応じて異なります。
-
オブジェクト(表または索引。デフォルトは表)の圧縮率を取得する構文。
DBMS_COMPRESSION.GET_COMPRESSION_RATIO ( scratchtbsname IN VARCHAR2, ownname IN VARCHAR2, objname IN VARCHAR2, subobjname IN VARCHAR2, comptype IN NUMBER, blkcnt_cmp OUT PLS_INTEGER, blkcnt_uncmp OUT PLS_INTEGER, row_cmp OUT PLS_INTEGER, row_uncmp OUT PLS_INTEGER, cmp_ratio OUT NUMBER, comptype_str OUT VARCHAR2, subset_numrows IN NUMBER DEFAULT COMP_RATIO_MINROWS, objtype IN PLS_INTEGER DEFAULT OBJTYPE_TABLE);
-
BasicFile LOBとSecureFile LOBの圧縮率を取得する構文:
DBMS_COMPRESSION.GET_COMPRESSION_RATIO ( scratchtbsname IN VARCHAR2, tabowner IN VARCHAR2, tabname IN VARCHAR2, lobname IN VARCHAR2, partname IN VARCHAR2, comptype IN NUMBER, blkcnt_cmp OUT PLS_INTEGER, blkcnt_uncmp OUT PLS_INTEGER, lobcnt OUT PLS_INTEGER, cmp_ratio OUT NUMBER, comptype_str OUT VARCHAR2, byte_comp_ratio OUT NUMBER, total_time OUT NUMBER subset_numrows IN NUMBER DEFAULT COMP_RATIO_LOB_MAXROWS);
-
表のすべての索引の圧縮率を取得する構文。圧縮率はコレクションとして戻されます。
DBMS_COMPRESSION.GET_COMPRESSION_RATIO ( scratchtbsname IN VARCHAR2, ownname IN VARCHAR2, tabname IN VARCHAR2, comptype IN NUMBER, index_cr OUT DBMS_COMPRESSION.COMPRECLIST, comptype_str OUT VARCHAR2, subset_numrows IN NUMBER DEFAULT COMP_RATIO_INDEX_MINROWS);
-
IOTの圧縮率を取得する構文。
DBMS_COMPRESSION.GET_COMPRESSION_RATIO ( scratchtbsname IN VARCHAR2, ownname IN VARCHAR2, objname IN VARCHAR2, subobjname IN VARCHAR2, comptype IN NUMBER, iotcomp_cr OUT DBMS_COMPRESSION.COMPRECLIST, comptype_str OUT VARCHAR2, subset_numrows IN NUMBER DEFAULT COMP_RATIO_INDEX_MINROWS);
パラメータ
表46-4 GET_COMPRESSION_RATIOプロシージャのパラメータ
パラメータ | 説明 |
---|---|
|
分析に使用できる一時スクラッチ表領域。 |
|
分析する表のスキーマ。 |
|
分析する表の名前。 |
|
オブジェクト名 |
|
オブジェクトのパーティションまたはサブパーティションの名前。 |
|
分析を実行する対象の圧縮タイプ。 オブジェクトが索引の場合、有効な圧縮タイプは、 ノート: |
|
表の圧縮されたサンプルに使用されるブロック数。 |
|
表の圧縮解除されたサンプルに使用されるブロック数。 |
|
表の圧縮されたサンプルにあるブロック内の行数。 |
|
表の圧縮解除されたサンプルにあるブロック内の行数。 |
|
圧縮比、 |
|
圧縮タイプを説明する文字列。 |
|
圧縮比を見積もるためにサンプリングされた行数。 |
|
|
|
LOB列名 |
|
パーティション化された表の場合は、関連したパーティション名。 |
|
圧縮比を見積もるために実際にサンプリングされたLOBの数。 |
|
索引のリストおよび見積り済の圧縮率。 |
iotcomp_cr |
IOTの圧縮率 最初のオブジェクトには、IOT全体の圧縮率が含まれます。 2番目のオブジェクトには、IOTの最上位索引セクション(オーバーフロー・セグメントを除く)の圧縮率のみが含まれます。 |
byte_comp_ratio |
LOBバイト・レベルでの圧縮率を提示します。 |
total_time |
表内のLOBデータを圧縮するためにかかる推定時間を提示します(時間単位)。 |
例
次の例は、高度な行圧縮の圧縮率を推定する方法を示しています。
SET SERVEROUTPUT ON
DECLARE
1_blkcnt_cmp PLS_INTEGER;
1_blkcnt_uncmp PLS_INTEGER;
1_row_cmp PLS_INTEGER;
1_row_uncmp PLS_INTEGER;
1_cmp_ratio NUMBER;
1_comptype_str VARCHAR2(32767);
BEGIN
DBMS_COMPRESSION.GET_COMPRESSION_RATIO (
scratchtbsname => 'USERS' ,
ownname => 'TEST' ,
objname => 'SALES' ,
subobjname => NULL ,
comptype => DBMS_COMPRESSION.COMP_ADVANCED,
blkcnt_cmp => 1_blkcnt_cmp,
blkcnt_uncmp => 1_blkcnt_uncmp,
row_cmp => 1_row_cmp,
row_uncmp => 1_row_uncmp,
cmp_ratio => 1_cmp_ratio,
comptype_str => 1_comptype_str,
subset_numrows => DBMS_COMPRESSION.comp_ratio_minrows,
objtype => DBMS_COMPRESSION.objtype_table
);
DBMS_OUTPUT.put_line( 'Number of blocks used by the compressed sample of the object : ' || 1_blkcnt_cmp);
DBMS_OUTPUT.put_line( 'Number of blocks used by the uncompressed sample of the object : ' || 1_blkcnt_uncmp);
DBMS_OUTPUT.put_line( 'Number of rows in a block in compressed sample of the object : ' || 1_row_cmp);
DBMS_OUTPUT.put_line( 'Number of rows in a block in uncompressed sample of the object : ' || 1_row_uncmp);
DBMS_OUTPUT.put_line( 'Estimated Compression Ratio of Sample : ' || 1_cmp_ratio);
DBMS_OUTPUT.put_line( 'Compression Type : ' || 1_comptype_str);
END;
/
高度な行圧縮(表全体)の圧縮アドバイザ見積りの出力:
Number of blocks used by the compressed sample of the object : 165 Number of blocks used by the uncompressed sample of the object : 629 Number of rows in a block in compressed sample of the object : 599 Number of rows in a block in uncompressed sample of the object : 157 Estimated Compression Ratio of Sample : 3.8 Compression Type : “Compress Advanced”
次の例は、拡張索引圧縮(低)の圧縮率を見積もる方法を示しています。
SET SERVEROUTPUT ON
DECLARE
1_blkcnt_cmp PLS_INTEGER;
1_blkcnt_uncmp PLS_INTEGER
1_row_cmp PLS_INTEGER;
1_row_uncmp PLS_INTEGER;
1_cmp_ratio NUMBER;
1_comptype_str VARCHAR2(32767);
BEGIN
DBMS_COMPRESSION.GET_COMPRESSION_RATIO (
scratchtbsname => 'USERS' ,
ownname => 'TEST' ,
objname => 'SALES_IDX' ,
subobjname => NULL ,
comptype => DBMS_COMPRESSION.COMP_INDEX_ADVANCED_LOW,
blkcnt_cmp => 1_blkcnt_cmp,
blkcnt_uncmp => 1_blkcnt_uncmp,
row_cmp => 1_row_cmp,
row_uncmp => 1_row_uncmp,
cmp_ratio => 1_cmp_ratio,
comptype_str => 1_comptype_str,
subset_numrows => DBMS_COMPRESSION.comp_ratio_minrows,
objtype => DBMS_COMPRESSION.objtype_index
);
DBMS_OUTPUT.put_line( 'Number of blocks used by the compressed sample of the object : ' || 1_blkcnt_cmp);
DBMS_OUTPUT.put_line( 'Number of blocks used by the uncompressed sample of the object : ' || 1_blkcnt_uncmp);
DBMS_OUTPUT.put_line( 'Number of rows in a block in compressed sample of the object : ' || 1_row_cmp);
DBMS_OUTPUT.put_line( 'Number of rows in a block in uncompressed sample of the object : ' || 1_row_uncmp);
DBMS_OUTPUT.put_line( 'Estimated Compression Ratio of Sample : ' || 1_cmp_ratio);
DBMS_OUTPUT.put_line( 'Compression Type : ' || 1_comptype_str);
END;
/
拡張索引圧縮(低)の圧縮アドバイザ見積りの出力:
Number of blocks used by the compressed sample of the object : 243 Number of blocks used by the uncompressed sample of the object : 539 Number of rows in a block in compressed sample of the object : 499 Number of rows in a block in uncompressed sample of the object : 145 Estimated Compression Ratio of Sample : 2.2 Compression Type : “Compress Advanced Low”
次の例は、拡張LOB圧縮(中)の圧縮率を見積もる方法を示しています。
SET SERVEROUTPUT ON
DECLARE
1_blkcnt_cmp PLS_INTEGER;
1_blkcnt_uncmp PLS_INTEGER;
1_row_cmp PLS_INTEGER;
1_lobcnt PLS_INTEGER;
1_cmp_ratio NUMBER;
1_comptype_str VARCHAR2(32767);
BEGIN
DBMS_COMPRESSION.GET_COMPRESSION_RATIO (
scratchtbsname => 'USERS' ,
tabowner => 'TEST' ,
tabname => 'PARTS' ,
lobname => 'PART_DESCRIPTION' ,
partname => NULL ,
comptype => DBMS_COMPRESSION.COMP_LOB_MEDIUM,
blkcnt_cmp => 1_blkcnt_cmp,
blkcnt_uncmp => 1_blkcnt_uncmp,
row_cmp => 1_row_cmp,
lobcnt => 1_lobcnt,
cmp_ratio => 1_cmp_ratio,
comptype_str => 1_comptype_str,
subset_numrows => DBMS_COMPRESSION.comp_ratio_lob_maxrows
);
DBMS_OUTPUT.put_line( 'Number of blocks used by the compressed sample of the object : ' || 1_blkcnt_cmp);
DBMS_OUTPUT.put_line( 'Number of blocks used by the uncompressed sample of the object : ' || 1_blkcnt_uncmp);
DBMS_OUTPUT.put_line( 'Number of rows in a block in compressed sample of the object : ' || 1_row_cmp);
DBMS_OUTPUT.put_line( 'Number of LOBS actually sampled : ' || 1_lobcnt);
DBMS_OUTPUT.put_line( 'Estimated Compression Ratio of Sample : ' || 1_cmp_ratio);
DBMS_OUTPUT.put_line( 'Compression Type : ' || 1_comptype_str);
END;
/
拡張LOB圧縮(中)の圧縮アドバイザ見積りの出力:
Number of blocks used by the compressed sample of the object : 199 Number of blocks used by the uncompressed sample of the object : 389 Number of rows in a block in compressed sample of the object : 293 Number of LOBS actually sampled : 55 Estimated Compression Ratio of Sample : 1.9 Compression Type : “Compress Medium”
次の例は、IOTの圧縮率を見積もる方法を示しています。
SET SERVEROUTPUT ON
DECLARE
bcmp INTEGER;
buncmp INTEGER;
rowcmp INTEGER;
rowuncmp INTEGER;
cr NUMBER;
cstr VARCHAR2(2000);
iotcomp_cr DBMS_COMPRESSION.COMPRECLIST;
BEGIN
DBMS_COMPRESSION.GET_COMPRESSION_RATIO (
scratchtbsname => 'USERS',
ownname => 'TEST',
objname => 'SALES',
subobjname => NULL,
comptype => DBMS_COMPRESSION.COMP_INDEX_ADVANCED_LOW,
iotcomp_cr => iotcomp_cr,
comptype_str => cstr,
subset_numrows => DBMS_COMPRESSION.COMP_RATIO_ALLROWS
);
--information about the index and the overflow segment
DBMS_OUTPUT.put_line( 'Number of blocks used by the compressed sample of the IOT table : ' || iotcomp_cr(1).blkcnt_cmp);
DBMS_OUTPUT.put_line( 'Number of blocks used by the uncompressed sample of the IOT table : ' || iotcomp_cr(1).blkcnt_uncmp);
DBMS_OUTPUT.put_line( 'Average number of rows in a block in the compressed sample of the IOT table : ' || iotcomp_cr(1).row_cmp);
DBMS_OUTPUT.put_line( 'Average number of rows in a block in the uncompressed sample of the IOT table : ' || iotcomp_cr(1).row_uncmp);
DBMS_OUTPUT.put_line( 'Estimated Compression Ratio of the sample : ' || iotcomp_cr(1).cmp_ratio);
--information about the index segment
DBMS_OUTPUT.put_line( 'Number of blocks used by the compressed sample of the index segment of the IOT table : ' || iotcomp_cr(2).blkcnt_cmp);
DBMS_OUTPUT.put_line( 'Number of blocks used by the uncompressed sample of the index segment of the IOT table : ' || iotcomp_cr(2).blkcnt_uncmp);
DBMS_OUTPUT.put_line( 'Average number of rows in a block in the compressed sample of the index segment of the IOT table : ' || iotcomp_cr(2).row_cmp);
DBMS_OUTPUT.put_line( 'Average number of rows in a block in the uncompressed sample of the index segment of the IOT table : ' || iotcomp_cr(2).row_uncmp);
DBMS_OUTPUT.put_line( 'Estimated Compression Ratio of the sample : ' || iotcomp_cr(2).cmp_ratio);
END;
/
IOTの圧縮率の出力:
Number of blocks used by the compressed sample of the IOT table : 5027 Number of blocks used by the uncompressed sample of the IOT table : 7950 Average number of rows in a block in the compressed sample of the IOT table : 199 Average number of rows in a block in the uncompressed sample of the IOT table : 126 Estimated Compression Ratio of the sample : 1.58 Number of blocks used by the compressed sample of the index segment of the IOT table : 3238 Number of blocks used by the uncompressed sample of the index segment of the IOT table : 6161 Average number of rows in a block in the compressed sample of the index segment of the IOT table : 309 Average number of rows in a block in the uncompressed sample of the index segment of the IOT table : 162 Estimated Compression Ratio of the sample : 1.9
次の例は、BasicFile LOBとSecureFile LOBの圧縮率を推定する方法を示しています。23cリリース以降、BasicFile LOBの圧縮率も推定できるようになりました。この例では、23cリリースで導入された新しいパラメータbyte_comp_ratio
とtotal_time
の使用方法についても説明しています。
DECLARE
bcmp INTEGER;
buncmp INTEGER;
lobcmp INTEGER;
cr NUMBER;
cstr VARCHAR2(2000);
byte_comp_ratio NUMBER;
total_time NUMBER;
BEGIN
DBMS_COMPRESSION.GET_COMPRESSION_RATIO (
scratchtbsname => 'SYSAUX',
tabowner => 'T',
tabname => 'T5',
lobname => 'DATA',
partname => 'P1',
comptype => dbms_compression.COMP_LOB_MEDIUM,
blkcnt_cmp => bcmp,
blkcnt_uncmp => buncmp,
lobcnt => lobcmp,
cmp_ratio => cr,
comptype_str => cstr,
subset_numrows => -1,
byte_comp_ratio => byte_comp_ratio,
total_time => total_time
);
DBMS_OUTPUT.put_line('Estimated compression ratio of sample: '||cr);
DBMS_OUTPUT.put_line('Number of blocks used by the uncompressed sample of the LOB: '||buncmp);
DBMS_OUTPUT.put_line('Estimated number of blocks used by compressed sample of the LOB: '||bcmp);
DBMS_OUTPUT.put_line('Estimated compression ratio at the byte level: '||byte_comp_ratio);
DBMS_OUTPUT.put_line('Estimated time to compress the LOB data in the table: '||total_time|| ' hrs');
end;
BasicFile LOBとSecureFile LOBの圧縮率の出力。
Estimated compression ratio of sample: 1
Number of blocks used by the uncompressed sample of the LOB: 1240
Estimated number of blocks used by compressed sample of the LOB: 1240
Estimated compression ratio at the byte level: 1.36890022783308
Estimated time to compress the LOB data in the table: .00005245645896343059487970173760270976565028 hrs
この例の出力では、圧縮の前後でブロック数は同じため、ブロック・レベルの圧縮率のcmp_ratio
が1になります。ただし、圧縮の前後でLOBに使用される実際のバイト数を比較するバイト・レベルの圧縮率byte_comp_ratio
は1.36になっています。たとえば、圧縮前のLOBが1000バイトを使用しているとします。バイト・レベルでの推定圧縮率は1.36です。これは、圧縮後のLOBには約736バイトが使用されることを示します。
使用上のノート
- プロシージャは、スクラッチ表領域に異なる表を作成し、これらのオブジェクトで分析を実行します。ユーザー指定の表では何も変更しません。
-
23c以降、この機能が拡張されていて、少ない領域の使用でLOBの圧縮率をより速く推定するようになりました。より正確な結果を得るには、次のコマンドを実行して古いメソッドに切り替えます。圧縮率を計算する古いメソッドでは、結果を返すまでに時間がかかり、より多くの領域が使用されます。
alter session set "_kdlf_new_compression_adv"= FALSE;
46.5.2 GET_COMPRESSION_TYPEファンクション
このファンクションは、特定の行に対する圧縮タイプを戻します。行が連鎖している場合は、ファンクションは先頭の圧縮タイプのみを戻し、先頭は異なる圧縮が可能であるため、中間や末尾は調べません。
構文
DBMS_COMPRESSION.GET_COMPRESSION_TYPE ( ownname IN VARCHAR2, tabname IN VARCHAR2, row_id IN ROWID, subobjname IN VARCHAR2 DEFAULT NULL)) RETURN NUMBER;
パラメータ
表46-5 GET_COMPRESSION_TYPEファンクションのパラメータ
パラメータ | 説明 |
---|---|
|
表のスキーマ名。 |
|
表の名前。 |
|
行のROWID。 |
|
表パーティションまたは表サブパーティションの名前。 |
戻り値
圧縮タイプを示すフラグ(表46-1を参照)。