EXPLAINリクエスト修飾子と標準インデックス アクセス - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQLリクエストおよびトランザクション処理

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Published
2021年7月
Language
日本語
Last Update
2021-09-23
dita:mapPath
ja-JP/uqf1592445067244.ditamap
dita:ditavalPath
ja-JP/wrg1590696035526.ditaval
dita:id
B035-1142
Product Category
Software
Teradata Vantage

EXPLAINリクエスト修飾子はテーブルに対して定義されているインデックスが正しく定義されており、効率的に使用されているかを特定する上で役立ちます。

他の結合例に示したように、EXPLAINではリクエストを処理するために使用できる固有インデックスを特定します。

条件式が非固有セカンダリ インデックスを使用する場合、EXPLAINは、データ行検索でスプールを使用するか、それともビット マッピングを使用するかについても示します。

次の例でこの機能を説明します。2つのリクエストと対応するEXPLAINの記述を比較してください。

なお、最初のリクエストではテーブルは小さいため(また、dept_nosalaryyrs_exp、およびed_levは個別の非固有インデックスとして定義)、フル テーブル スキャンはデータ行のアクセスに使用されません。

ただし、2番目のリクエストでは、テーブルは極めて大きい ため、最適化ルーチンは、サブテーブルの行IDのビットマッピングがより高速な検索方法であると判定します。

フル テーブル スキャンの例

このリクエストでは次のEXPLAINレポートが返されます。

EXPLAIN 
SELECT COUNT(*)
FROM employee
WHERE dept_no = 500
AND salary > 25000
AND yrs_exp >= 3
AND ed_lev >= 12;
Explanation 
--------------------------------------------------------
1) First, we lock PERSONNEL.employee for read on a resereved 
   RowHash to prevent global deadlock.
2) Next, we lock PERSONNEL.employee for read.
3) We do an all-AMPs SUM step to aggregate from PERSONNEL.Employee by
   way of an all-rows scan with a condition of
   ("(PERSONNEL.employee.DeptNo = 500) AND
   ((PERSONNEL.employee.Salary > 25000.00) AND
   ((PERSONNEL.employee.YrsExp >= 3) AND
   (PERSONNEL.employee.EdLev >= 12 )))").
   Aggregate Intermediate Results are computed globally, then placed in
   Spool 2.
4) We do an all-AMPs RETRIEVE step from Spool 2 (Last Use) by way of
   an all-rows scan into Spool 1, which is built locally on the AMPs.
   The size of Spool 1 is estimated with high confidence to be 1 row (32 bytes). 
   The estimated time for this step is 0.06 seconds.
5) Finally, we send out an END TRANSACTION step to all AMPs involved in
   processing the request.
-> The contents of Spool 1 are sent back to the user as the result of statement 1.

この説明内の新しい用語は、次のように定義されます。

定義
SUM step to aggregate (集約のためのSUMステップ) テーブルは1行ごとに検索され、行が検出された各AMPに対して修飾行がカウントされます。また、各カウントはローカル スプールに保持されます。
computed globally (グローバルに計算する) この最終計算にはすべての中間スプール データが関与します。

固有プライマリ インデックスの例

EXPLAINリクエスト修飾子はこのリクエストに対して次の応答を生成します。

EXPLAIN 
SELECT name, dept_no
FROM employee
WHERE empno = 10009;
Explanation
-----------------------------------------------------
1) First, we do a single-AMP RETRIEVE step from Personnel.Employee by way of the unique primary index "PERSONNEL.Employee.EmpNo = 10009" with no residual conditions. The estimated time for this step is 0.04 seconds.
-> The row is sent directly back to the user as the result of statement 1. The total estimated time is 0.04 seconds.

非固有インデックスに対する条件を使用するSELECTの例

この例のWHERE条件は非固有インデックスとして定義されている列に基づいています。なお、システムがテーブルにREADロックをかけます。

EXPLAINリクエスト修飾子はこのリクエストに対して次の応答を生成します。

EXPLAIN 
SELECT emp_no, dept_no
FROM employee
WHERE name = 'Smith T';
Explanation
-----------------------------------------------------------------------
1) First, we lock PERSONNEL.employee for read on a
   RowHash to prevent global deadlock.
2) Next, we lock PERSONNEL.employee for read.
3) We do an all-AMPs RETRIEVE step from PERSONNEL.employee by way of
   index # 4 "PERSONNEL.employee.Name = 'Smith T '" with no residual
   conditions into Spool 1 (group_amps), which is built locally on
   the AMPs. The size of Spool 1 is estimated with low confidence to
   be 33,563 rows (1,443,209 bytes). The estimated time for this
   step is 0.34 seconds.
4) Finally, we send out an END TRANSACTION step to all AMPs involved
   in processing the request.
-> The contents of Spool 1 are sent back to the user as the result of
   statement 1. The total estimated time is 0.34 seconds.

固有セカンダリ インデックスに対する条件を使用するSELECTの例

Employeeテーブルにもう1つの列(socsecno)があると想定します。soc_sec_noは固有セカンダリ インデックスとして定義されています。

WHERE条件がこの列に基づいている場合、EXPLAINリクエスト修飾子によりこのリクエストに対して次の応答が生成されます。

EXPLAIN 
SELECT name, emp_no
FROM employee
WHERE soc_sec_no = '123456789';
Explanation
-----------------------------------------------------
1) First, we do a two-AMP RETRIEVE step from PERSONNEL.Employee by way
   of unique index # 20 "PERSONNEL.Employee.socSecNo = 123456789" with 
   no residual conditions. The estimated time for this step 
   is 0.09 seconds.
-> The row is sent directly back to the user as the result of statement 1.
   The total estimated time is 0.09 seconds.

ビットマッピングを使用するインデックス アクセスの例

このリクエストでは次のEXPLAINレポートが返されます。

EXPLAIN 
SELECT COUNT(*)
FROM main
WHERE num_a = '101'    
AND num_b  = '02'    
AND kind  = 'B'    
AND event = '001';
Explanation 
------------------------------------------------------ 
...
2) Next, we do a BMSMS (bit map set manipulation) step that intersects
   the following row id bit maps: 
   1) The bit map built for TESTING.Main by way of index # 12
      "TESTING.Main.Kind = ’B’".
   2) The bit map build for TESTING.Main by way of index # 8
      "TESTING.Main.Num_B = ’02’". 
   3) The bit map built for TESTING.Main by way of index # 16
      "TESTING.Main.Event =’001’". 
   The resulting bit map is placed in Spool 3. The estimated time
   for this step is 17.77 seconds.
3) We do a SUM step to aggregate from TESTING.Main by way of
   index # 4 "TESTING.Main.Num_A = ’101’" and the bit map in Spool
   3 (Last Use) with a residual condition of
   ("(TESTING.Main.Num_B = ’02’) and
   ((TESTING.Main.Kind = ’B’) and TESTING.Main.Event = ’001’))").
   Aggregate Intermediate Results are  computed globally, then
   placed in Spool 2.
4) We do an all-AMPs RETRIEVE step from Spool 2 (Last Use) by way
   of an all-rows scan into Spool 1, which is built locally on the
   AMPs. The size of Spool 1 is estimated to be 20 rows. The
   estimated time for this step is 0.11 seconds.
...

この説明内の新しい用語は、次のように定義されます。

定義
BMSMS (bit map set manipulation step) that intersects the following Row-Id bit maps: (次の行IDビットマップをAND演算するBMSMS(ビットマップ集合操作ステップ))

The bit map built for … by way of index # n … (インデックス # n…により…のためにビルドされたビットマップ)

The bit map built for … by way of index # n … (インデックス # n…により…のためにビルドされたビットマップ)

各非固有セカンダリ インデックス サブテーブルで、各データ行IDに0-32,767までの数字が割り当てられます。この数字は各修飾行がオンであるビット マップにインデックスとして使用されます。

BMSMSでは、修飾行のセットのAND演算が論理AND演算をそのセットのビットマップ表現に適用することによって計算するように指定します。

residual condition (残余条件) 選択行は1つ以上の条件式によりさらに修飾されます。