EXPLAINリクエスト修飾子と結合処理 - Advanced SQL Engine - Teradata Database

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

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
2020年6月
Language
日本語
Last Update
2021-03-30
dita:mapPath
ja-JP/ykx1561500561173.ditamap
dita:ditavalPath
ja-JP/ykx1561500561173.ditaval
dita:id
B035-1142
Product Category
Software
Teradata Vantage

サンプルの結合リクエストに適用すると、次の説明がEXPLAINによって生成されます。

各説明の前にリクエストの構文を、後ろに表示内の新しい用語のリストを記載します。

プロダクト ジョインの例

このリクエストには固有プライマリ インデックスの値に基づくWHERE条件があります。プロダクト ジョインが使用されている場合でも効率的な処理が生成されます。

EXPLAIN 
SELECT Hours, EmpNo, Description
FROM Charges, Project
WHERE Charges.Proj_Id = 'ENG-0003'
AND Project.Proj_Id = 'ENG-0003'    
AND Charges.WkEnd > Project.DueDate;

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

Explanation 
--------------------------------------------------------
...
2) Next, we do a single-AMP RETRIEVE step from PERSONNEL.Project
   by way of the unique primary index 
   "PERSONNEL.Project.Proj_Id = ’ENG-003’" with no residual
   conditions into Spool 2, which is duplicated on all AMPs.
   The size of Spool 2 is estimated to be 4 rows. The estimated
   time for this step is 0.07 seconds.
3) We do an all AMPs JOIN step from Spool 2 (Last Use) by way of
   an all-rows scan, which is joined to PERSONNEL.Charges with a
   condition of ("PERSONNEL.Charges.Proj_Id = ’ENG-0003’"). 
   Spool 2 and PERSONNEL.Charges are joined using a product join,
   with a join condition of
   ("PERSONNEL.Charges.WkEnd > Spool_2.DueDate"). The result
   goes into Spool 1, which is built locally on the AMPs. The size
   of Spool 1 is estimated to be 6 rows. The estimated time for this
   step is 0.13 seconds.
...

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

定義
single-AMP RETRIEVE step from…by way of the unique primary index (固有プライマリ インデックスによる…からの単一AMP検索ステップ) ハッシュ格納されている固有プライマリ インデックスの値を元に、単一AMP操作でテーブルの単一行が選択されます。
duplicated on all AMPs (全AMP上で複製される) 結合条件に基づき最初のテーブルから選択されたスプール ファイルの内容は、結合条件のもう一方のテーブル データがある全AMP上に複製されます。
all-AMPs JOIN step…by way of an all-rows scan (全行スキャンによる全AMP結合ステップ…) 行が常駐する各AMP上でテーブルの行が1行ごとに検索されます。結合条件を満たす行がスプールされている行に結合されます。
condition of … (…の条件) スプール行と選択された行の結合を修飾するために使用する中間条件(全体の結合条件と比較する)。
product join(プロダクト ジョイン) Teradata Databaseが実行する結合処理の1つの方式。

マージ結合の例

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

EXPLAIN 
SELECT Name, DeptName, Loc
FROM Employee, Department
WHERE Employee.DeptNo = Department.DeptNo;
Explanation 
--------------------------------------------------------
...
2) Next, we do an all-AMPs RETRIEVE step from
   PERSONNEL.Employee by way of an all-rows scan with no
   residual conditions into Spool 2, which is redistributed
   by hash code to all AMPs. Then we do a SORT to order Spool
   2 by row hash. The size of Spool 2 is estimated to be 8 rows.
   The estimated time for this step is 0.10 seconds.
3) We do an all-AMPs JOIN step from PERSONNEL.Department by way
   of a RowHash match scan with no residual conditions, which is
   joined to Spool 2 (Last Use). PERSONNEL.Department and Spool 2
   are joined using a merge join, with a join condition of
   ("Spool_2.DeptNo = PERSONNEL.Department.DeptNo"). The result
   goes into Spool 1, which is built locally on the AMPs. The 
   size of Spool 1 is estimated to be 8 rows. The estimated time
   for this step is 0.11 seconds.
...

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

定義
マージ結合 Teradata Databaseにより使用される結合方式の1つ。

ハッシュ結合の例

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

EXPLAIN 
SELECT Employee.EmpNum,Department.DeptName, Employee.Salary
FROM Employee, Department
WHERE Employee.Location = Department.Location;
Explanation 
-------------------------------------------
...
4) We do an all-AMPs RETRIEVE step from PERSONNEL.Employee by way of
   an all-rows scan with no residual conditions into Spool 2 fanned out
   into 22 hash join partitions, which is redistributed by hash code to
   all AMPs. The size of Spool 2 is estimated to be 3,995,664 rows.
   The estimated time for this step is 3 minutes and 54 seconds.
5) We do an all-AMPs RETRIEVE step from PERSONNEL.Department by way of
   an all-rows scan with no residual conditions into Spool 3 fanned out
   into 22 hash join partitions, which is redistributed by hash code to
   all AMPs. The size of Spool 3 is estimated to be 4,000,256 rows. The
   estimated time for this step is 3 minutes and 54 seconds.
6) We do an all-AMPs JOIN step from Spool 2 (Last Use) by way of an
   all-rows scan, which is joined to Spool 3 (Last Use). Spool 2 and
   Spool 3 are joined using a hash join of 22 partitions, with a join
   condition of ("Spool_2.Location = Spool_3.Location"). The result 
   goes into Spool 1, which is built locally on the AMPs. The result
   spool field will not be cached in memory. The size of Spool 1 is
   estimated to be 1,997,895,930 rows. The estimated time for this
   step is 4 hours and 42 minutes.
...

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

定義
ハッシュ結合 Teradata Databaseが実行する結合処理の1つの方式。

入れ子結合の例

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

EXPLAIN 
SELECT dept_name, name, yrs_exp
FROM employee, department
WHERE employee.emp_no  = department.mgr_no
AND   department.dept_no = 100;
Explanation 
-------------------------------------------------------
1) First, we do a single AMP JOIN step from PERSONNEL.Department by way of the unique primary index "PERSONNEL.Department.Dept_No = 100" with no residual condition which is joined to PERSONNEL.Employee by way of the unique primary index "PERSONNEL.Employee.Emp_No = PERSONNEL.Department.Mgr_No". PERSONNEL.Department and PERSONNEL.Employee are joined using a nested join. The result goes into Spool 1, which is built locally on that AMP. The size of Spool 1 is estimated to be 1 rows. The estimated time for this step is 0.10 seconds.
...

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

定義
single-AMP JOIN step from…by way of the unique primary index (固有プライマリ インデックスによる…からの単一AMP結合ステップ) そのテーブルに対して定義されている固有インデックスの値を使用して1つのAMPの1行が選択されます。

別のAMP上の第2のテーブルの行の固有プライマリ インデックスの値までハッシュする行の値を使用して、最初の行が2番目の行と結合されます (テーブルが固有プライマリ インデックスによりアクセスされるときは、Explainテキストに明示的に記されていない場合でもテーブル上の行ハッシュ ロックが示唆されます)。

nested join(入れ子結合) Teradata Databaseが実行する結合処理の1つの方式。

排他マージ結合の例

この例のリクエストはプライマリ テーブルからのみの列を選択します。

Subquery を通じて結合対象のテーブルから追加の行が選択されると(例えば、リクエストがSELECT name, dept_no, loc FROM employee, departmentである場合)、結果は直積になります。

EXPLAIN 
SELECT name, dept_no
FROM employee
WHERE dept_no NOT IN (SELECT dept_no
                      FROM department
                      WHERE loc = 'CHI')
ORDER BY name;

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

Explanation 
--------------------------------------------------------
...
2) Next, we execute the following steps in parallel.
   1) We do an all-AMPs RETRIEVE step from 
      PERSONNEL.Department by way of an all-rows
      scan with a condition of 
      ("PERSONNEL.Department.Loc = ’CHI’") into Spool 2, 
      which is redistributed by hash code to all AMPs. Then we
      do a SORT to order Spool 2 by row hash and the sort key
      in spool field1 eliminating duplicate rows. The size of
      Spool 2 is estimated to be 4 rows. The estimated time for
      this step is 0.07 seconds.
   2) We do an all-AMPs RETRIEVE step from PERSONNEL.Employee by
      way of an all-rows scan with no residual conditions into
      Spool 3, which is redistributed by hash code to all AMPs.
      Then we do a SORT to order Spool 3 by row hash. The size
      of Spool 3 is estimated to be 8 rows. The estimated time
      for this step is 0.10 seconds.
3) We do an all-AMPs JOIN step from Spool 3 (Last Use) by way of
   Spool 3 an all-rows scan, which is joined to Spool 2 (Last Use). 
   and Spool 2 are joined using an exclusion merge join, with a
   join condition of ("Spool_3.Dept_No = Spool_2.Dept_No"). The
   result goes into Spool 1, which is built locally on the AMPs.
   Then we do a SORT to order Spool 1 by the sort key in spool
   field1. The size of Spool 1 is estimated to be 8 rows. The
   estimated time for this step is 0.13 seconds.
...

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

定義
SORT to order Spool 2 by row hash and the sort key in spool field1 eliminating duplicate rows ... (スプールfield1での行ハッシュおよびソート キーによるスプール2を順序付けるソートで、重複行を削除する...) スプールの行は、重複行を削除するために固有性ソートを使用してハッシュ コード順に並べ替えられます。値の固有性はスプールfield1のデータに基づいています。

スプールfield1の内容は問合わせに依存し、次のいずれかを構成している可能性があります。

  • スプール行のすべてのフィールドの連結(SELECT DISTINCTによる問合わせを使用する。または、UNION、INTERSECT、MINUS操作を含む)。
  • スプール行が形成されるデータ行を特定する行IDの連結(subquery を含む複雑な問合わせに使用される)。
  • 固有に定義されるスプール行のその他の値(集約およびsubquery を含む複雑な問合わせに使用される)。
SORT to order Spool 1 by the sort key in spool field1 (スプールfield1でのソート キーによるSpool 1を順序付けするソート) この最後のソートは、プライマリSELECTリクエストに指定されている「ORDER BY」句に対する応答です。
exclusion merge join(排他マージ結合) Teradata Databaseが実行する結合処理の1つの方式。

subquery に基づく条件を使用するSELECTの例

この例では、結合条件となる制約はsubquery 述部によって定義され、ORDER BY句によりソート後の結果が指定されます。

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

EXPLAIN 
SELECT name, emp_no
FROM employee
WHERE emp_no IN (SELECT emp_no
                 FROM charges)
ORDER BY name;
Explanation
--------------------------------------------------------------------
...
3) We lock PERSONNEL.charges for read, and we lock PERSONNEL.employee
   for read.
4) We do an all-AMPs RETRIEVE step from PERSONNEL.charges by way of an
   all-rows scan with no residual conditions into Spool 2, which is
   redistributed by hash code to all AMPs. Then we do a SORT to order
   Spool 2 by row hash and the sort key in spool field1 eliminating
   duplicate rows. The size of Spool 2 is estimated to be 12 rows.
   The estimated time for this step is 0.15 seconds.
5) We do an all-AMPs JOIN step from PERSONNEL.employee by way of an
   all-rows scan with no residual conditions, which is joined to
   Spool 2 (Last Use). PERSONNEL.employee and Spool 2 are joined using
   an inclusion merge join, with a join condition of
   ("PERSONNEL.employee.EmpNo = Spool_2.EmpNo"). The result goes into
   Spool 1, which is built locally on the AMPs. Then we do a SORT to
   order Spool 1 by the sort key in spool field1. The size of Spool 1
   is estimated to be 12 rows. The estimated time for this step is 
   0.07 seconds.
...