EXPLAINリクエスト修飾子: 例 - Teradata Database - Teradata Vantage NewSQL Engine

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

Product
Teradata Database
Teradata Vantage NewSQL Engine
Release Number
16.20
Published
2019年3月
Language
日本語
Last Update
2019-10-29
dita:mapPath
ja-JP/arh1512079329802.ditamap
dita:ditavalPath
ja-JP/arh1512079329802.ditaval
dita:id
B035-1142
Product Category
Software
Teradata Vantage
この節ではさまざまな状況でのEXPLAINリクエスト修飾子の有効性を検討します。
これらの例の正確なEXPLAIN出力は、実行プランがシステム構成やTeradata Databaseリリースによって異なる場合があるため、実際の内容とは異なる場合があります。例を簡略化するために、一部のEXPLAIN句(map_nameなど)やステップ(ロックやEND TRANSACTIONなど)は、例の一部から省かれており、関連するステップのみが表示されています。

開発中の新しい問合わせを分析するために必ずEXPLAINレポートを使用してください。問合わせの構成方法での微妙な違いにより、同じ結果セットを返すために同じ時間を費やしても、リソースへの影響やパフォーマンスに大きな差が生じる可能性があります。

EXPLAINリクエスト修飾子の用語は、EXPLAINリクエスト修飾子句の用語で定義されています。

personnel.employeeテーブルを使用する例では、固有プライマリ インデックスをemp_no列に定義し、非固有セカンダリ インデックスをname列に定義するように定義されています。

ANSIセッション モードとTeradataセッション モードの更新の例

この例では、ANSIセッション モードで実行されるセッションとTeradataセッション モードで実行されるセッションとの間のEXPLAINの違いを示します。

EXPLAIN 
UPDATE Employee
SET deptno = 650
WHERE deptno = 640;

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

Explanation
--------------------------------------------------------------------
1) First, we lock PERSONNEL.employee for write
   on a reserved RowHash to prevent global deadlock.
2) Next, we lock PERSONNEL.employee for write.
3) We do an all-AMPs UPDATE from PERSONNEL.employee by way of an
   all-rows scan with a condition of
   ("PERSONNEL.employee.DeptNo = 640").
-> No rows are returned to the user as the result of statement 1.

Teradataセッション モードでは、EXPLAINが同じリクエストに対して次の応答を生成します。

Explanation
--------------------------------------------------------------------
1) First, we lock PERSONNEL.employee for write on a
   reserved RowHash to prevent global deadlock.
2) Next, we lock PERSONNEL.employee for write.
3) We do an all-AMPs UPDATE from PERSONNEL.employee by way of an
   all-rows scan with a condition of
   ("PERSONNEL.employee.DeptNo = 640").
4) Finally, we send out an END TRANSACTION step to all AMPs involved
   in processing the request.
-> No rows are returned to the user as the result of statement 1.

ANSIセッション モードでは、トランザクションはCOMMITされていないため、終了しません。一方、Teradataのセッション モードでは、トランザクションを終了するためにCOMMITは必要ありません。

少数AMP行の再配布の例

以下のように、マルチセット テーブルおよび2番目のテーブルを作成するとします。

CREATE MULTISET TABLE customer_order (customer_name CHAR(10), order_no INTEGER)
PRIMARY INDEX (customer_name);

CREATE TABLE order_detail (order_no INTEGER, product_name  CHAR(20))
PRIMARY INDEX (order_no);

EXPLAINリクエスト修飾子はステップ1で少数AMPテキストを生成します。これはステップで少数AMPが行再配布に使用されていることを示します。問合わせステップ1では、以下の要因のため、少数AMPが使用されます。

  • ステップが‘Smith’ (NUPI)の行を持つ単一のAMPで開始される、および
  • Smith行がorder_no columnのハッシュ コードによって再配布される、および
  • 再配布された行数が少なく、行が少数AMPにのみハッシュされる。
    EXPLAIN
    SELECT customer_name, product_name
    FROM customer_order CO, order_detail OD
    WHERE CO.customer_name = 'Smith' AND CO.order_no = OD.order_no;
    Explanation
    --------------------------------------------------------------------
      1) First, we do a single-AMP RETRIEVE step from JW.CO by way of
         the primary index "JW.CO.customer_name = 'Smith '" with a
         residual condition of ("NOT (JW.CO.order_no IS NULL)") into 
         Spool 2 (group_amps), which is redistributed by the hash code
         of (JW.CO.order_no) to few AMPs. Then we do a SORT to
         order Spool 2 by row hash. The size of Spool 2 is estimated
         with low confidence to be 2 rows (54 bytes). The estimated
         time for this step is 0.01 seconds.
      2) Next, we do a group-AMPs JOIN step from JW.OD by way of a
         RowHash match scan, which is joined to Spool 2 (Last Use) by
         way of a RowHash match scan. JW.OD and Spool 2 are joined using
         a merge join, with a join condition of
         ("order_no = JW.OD.order_no"). The result goes into Spool 1
         (group_amps), which is built locally on that AMP. The size of
         Spool 1 is estimated with index join confidence to be 3 rows
         (153 bytes). The estimated time for this step is 0.11 seconds.
      3) 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.11 seconds.

UNION ALLのワンステップ マルチソースRETRIEVE

5) TD_MAP1で次の2つのソースから全AMP RETRIEVEステップを実行します。a) ( "NOT (TEST.t1.a1 IS NULL)")の条件の全行スキャンによるTEST.t1。b) ( "NOT (TEST.t2.a2 IS NULL)")の条件の全行スキャンによるTEST.t2。
     The result goes into Spool 1 (all_amps), which is built
     locally on the AMPs.  The size of Spool 1 is estimated with
     low confidence to be 126 rows (3,150 bytes).  The estimated
     time for this step is 0.15 seconds.

ワンステップ マルチソースJOIN

6) 2つの左のソースからTD_Map1の全AMP JOINステップを実行します。これは、動的なハッシュ結合を使用して、全行スキャンによるTEST.t1に結合されます。左のソースを次に示します。a)結合条件("TEST.t1.b1 = a2")の全行スキャンによるSpool 3 (Last Use)。b)結合条件("TEST.t1.b1 = a3")の全行スキャンによるSpool 4 (Last Use)。
     The result goes into Spool 2 (group_amps), which is built
     locally on the AMPs.  The size of Spool 2 is estimated with
     no confidence to be 90 rows (2,880 bytes).  The estimated
     time for this step is 0.23 seconds.

ワンステップ マルチソースSUM

4) TD_MAP1で全AMP SUMステップを実行して、次の2つのソースから集計します。a)残余条件なしのシリンダ インデックス スキャンによるTEST.t1。b)残余条件なしのシリンダ インデックス スキャンによるTEST.t2。
     Aggregate Intermediate Results are computed globally, then
     placed in Spool 9 in TD_Map1.  The size of Spool 9 is
     estimated with high confidence to be 1 row (23 bytes).  The
     estimated time for this step is 0.18 seconds.