DYNAMIC 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

IPEによって生成された問合わせ計画は、動的問合わせ計画と呼ばれます。動的問合わせ計画は、説明されたリクエストに対して従来返される問合わせ計画ではありません。

IPEは、統計情報のフィードバックと、計画フラグメントの結果からのフィードバックを提供します。これにより、パーティション排除(行パーティション排除および列パーティション排除を参照)およびスパース結合インデックスの限定などの多くの最適化が可能になり、また推移閉包、述部の簡略化、実現不可能などの多くのクエリー リライト(各種のクエリー リライト方法について詳しくはクエリー リライト、統計、および最適化を参照)も可能になります。

動的EXPLAINレポートのリクエスト

リクエストの動的EXPLAINレポートを依頼する場合、キーワードEXPLAINに先行してキーワードDYNAMICを指定します。EXPLAINリクエスト修飾子のデフォルトはSTATICなので、動的EXPLAINレポートを返すには、ほとんどのサイトでDYNAMICを指定する必要があります。

EXPLAINキーワードの後にIN XMLキーワードを指定すると、レポートをXML形式で返すように要求できます。クエリーの実行時に使用される実際の計画は、EXPLAINの実行時からデータが変更されているため、EXPLAIN出力と異なる場合があります。

EXPLAINリクエスト修飾子の詳細については、<Teradata Vantage™ - SQLデータ操作言語、B035-1146>を参照してください。

または、DBQL EXPLAINプラン ロギング(DBQL XMLPlanロギングを含む)を使用します。これにより、クエリーの実行に使用される実際の計画が提供されます。DBQLは、任意の形式のEXPLAINリクエスト修飾子が前に置かれているリクエストはログに記録しませんが、動的問合わせ計画を使用するために最適化されているリクエストの追加情報(計画フラグメントの数や現在のステップが属する計画フラグメントなど)はログに記録します。

動的問合わせ計画のEXPLAINレポートのセキュリティに関する問題

IPEは、計画フラグメントの実行の中間結果を主問合わせに挿入して、動的問合わせ計画を生成します。動的問合わせ計画は、挿入されたリクエスト フラグメント定数を問合わせ述部の要素として処理します。EXPLAINレポートの中間結果が、その表示権限がない可能性があるエンド ユーザーに明らかにならないようにすることが望ましい場合があります。例えば、エンド ユーザーが、そのユーザーがSELECTアクセス権がない多数のビューまたはテーブルのデータを取得可能な別のビューに対するSELECTアクセス権があるという場合があります。

中間動的クエリー計画結果をマスクするようにシステムが設定されていると(デフォルト設定)、Vantageは、EXPLAINレポートにある中間結果の値を文字列:*に置き換えてマスクします。:*文字列とその意味について詳しくは、EXPLAINリクエスト修飾子句の用語を参照してください。

マスクされていない動的問合わせ計画のDYNAMIC EXPLAIN

この例では、マスクされていない動的計画を表示できるようにシステムで設定されていると想定しています。マスクされていない動的計画の場合、unmaskedという語は、中間結果をレポートするテキストがレポートから除去されていないことを意味します。以下のレポートでは、ステップ9にある条件("OPTBASE_PCTDB.t1.a1 < 10000")および("OPTBASE_PCTDB.t2.a2 <= 9999")の値100009999(太字で強調表示されています)がマスクされていないテキストです。

DYNAMIC EXPLAIN 
SELECT *
FROM t1, t2
WHERE t1.a1 < (SELECT MAX(t3.a3)
               FROM t3)
AND   t1.a1 = t2.a2;
Explanation
----------------------------------------------------------------------
The following is the dynamic explain for the request. 
...
5) We do an all-AMPs SUM step to aggregate from OPTBASE_PCTDB.t3 by
   way of an all-rows scan with no residual conditions. Aggregate
   Intermediate Results are computed globally, then placed in Spool 3.
   The size of Spool 3 is estimated with high confidence to be 1 row
   (19 bytes). The estimated time for this step is 0.02 seconds.
6) We do an all-AMPs RETRIEVE step from Spool 3 (Last Use) by way of
   an all-rows scan into Spool 1 (all_amps), which is built locally
   on the AMPs. The size of Spool 1 is estimated with high
   confidence to be 1 row (25 bytes). The estimated time for this
   step is 0.00 seconds.
7) We do an all-AMPs FEEDBACK RETRIEVE step from Spool 1 (Last Use)
   The size is estimated with high confidence to be 1 row (25 bytes).
   The estimated time for this step is 0.01 seconds. The actual size
   of Spool 1 is 1 row (25 bytes.)
8) We send an END PLAN FRAGMENT step for plan fragment 1. 
9) We do an all-AMPs JOIN step from 9999 partitions of
   OPTBASE_PCTDB.t1 by way of a RowHash match scan with a condition
   of ("OPTBASE_PCTDB.t1.a1 < 10000"), which is joined to
   OPTBASE_PCTDB.t2 by way of a RowHash match scan with a condition
   of ("OPTBASE_PCTDB.t2.a2 <= 9999"). OPTBASE_PCTDB.t1 and
   OPTBASE_PCTDB.t2 are joined using a sliding-window merge join,
   with a join condition of ("OPTBASE_PCTDB.t1.a1 =
   OPTBASE_PCTDB.t2.a2"). The input tables OPTBASE_PCTDB.t1 and
   OPTBASE_PCTDB.t2 will not be cached in memory, but
   OPTBASE_PCTDB.t1 is eligible for synchronized scanning. The
   result goes into Spool 1 (group_amps), which is built locally on
   the AMPs. The size of Spool 1 is estimated with low confidence to
   be 9,999 rows (649,935 bytes). The estimated time for this step
   is 8.24 seconds.
...

マスクされた動的問合わせ計画のDYNAMIC EXPLAIN

この例では、マスクされた動的計画をレポートすることがデフォルトで許可されていると想定しています。マスクされた動的計画の場合、maskedという語は、中間結果をレポートするテキストがレポートから除去されているということを意味します。これは、DBS制御フィールドの設定によって制御されます。

この動的計画のステップ9に示されているように、マスクされている値はEXPLAINテキストでは文字列:*によって表わされます。この文字列は、前述の例に示されていた100009999をマスクされた値に置き換えます。

DYNAMIC EXPLAIN 
SELECT *
FROM t1, t2
WHERE t1.a1 < (SELECT MAX(t3.a3) 
               FROM t3)
AND   t1.a1 = t2.a2;
Explanation
----------------------------------------------------------------------
The following is the dynamic explain for the request. 
...
5) We do an all-AMPs SUM step to aggregate from OPTBASE_PCTDB.t3 by
   way of an all-rows scan with no residual conditions. Aggregate
   Intermediate Results are computed globally, then placed in Spool 3.
   The size of Spool 3 is estimated with high confidence to be 1 row
   (19 bytes). The estimated time for this step is 0.02 seconds.
6) We do an all-AMPs RETRIEVE step from Spool 3 (Last Use) by way of
   an all-rows scan into Spool 1 (all_amps), which is built locally
   on the AMPs. The size of Spool 1 is estimated with high
   confidence to be 1 row (25 bytes). The estimated time for this
   step is 0.00 seconds. 
7) We do an all-AMPs FEEDBACK RETRIEVE step from Spool 1 (Last Use)
   The size is estimated with high confidence to be 1 row (25 bytes).
   The estimated time for this step is 0.01 seconds. The actual size
   of Spool 1 is 1 row (25 bytes). 
8) We send an END PLAN FRAGMENT step for plan fragment 1. 
9) We do an all-AMPs JOIN step from 9999 partitions of
   OPTBASE_PCTDB.t1 by way of a RowHash match scan with a condition
   of ("OPTBASE_PCTDB.t1.a1 < :*"), which is joined to
   OPTBASE_PCTDB.t2 by way of a RowHash match scan with a condition
   of ("OPTBASE_PCTDB.t2.a2 <= :*"). OPTBASE_PCTDB.t1 and
   OPTBASE_PCTDB.t2 are joined using a sliding-window merge join,
   with a join condition of ("OPTBASE_PCTDB.t1.a1 =
   OPTBASE_PCTDB.t2.a2"). The input tables OPTBASE_PCTDB.t1 and
   OPTBASE_PCTDB.t2 will not be cached in memory, but
   OPTBASE_PCTDB.t1 is eligible for synchronized scanning. The
   result goes into Spool 1 (group_amps), which is built locally on
   the AMPs. The size of Spool 1 is estimated with low confidence to
   be 9,999 rows (649,935 bytes). The estimated time for this step
   is 8.24 seconds.
...

動的計画の表示が許可されていないもののリクエストがIPEに適格な場合のDYNAMIC EXPLAIN

この例は、動的計画の表示に関するDBS制御フィールドの設定において、動的計画をレポートすることが許可されていない場合のDYNAMIC EXPLAINレポートを示しています。この場合、Vantageはリクエストに対して静的計画をレポートします。

DYNAMIC EXPLAIN 
SELECT *
FROM t1, t2
WHERE t1.a1 < (SELECT MAX(t3.a3)
               FROM t3)
AND   t1.a1 = t2.a2;
Explanation
-----------------------------------------------------------------------
This request is eligible for incremental planning and execution (IPE). The following is the static plan for the request. 
...
5) We do an all-AMPs SUM step to aggregate from OPTBASE_PCTDB.t3 by
   way of an all-rows scan with no residual conditions. Aggregate
   Intermediate Results are computed globally, then placed in Spool 3.
   The size of Spool 3 is estimated with high confidence to be 1 row
   19 bytes). The estimated time for this step is 0.02 seconds.
6) We do an all-AMPs RETRIEVE step from Spool 3 (Last Use) by way of
   an all-rows scan into Spool 1 (all_amps), which is built locally
   on the AMPs. The size of Spool 1 is estimated with high
   confidence to be 1 row (25 bytes). The estimated time for this
   step is 0.00 seconds.
7) We do an all-AMPs DISPATCHER RETRIEVE step from Spool 1 (Last Use)
   by way of an all-rows scan and send the rows back to the Dispatcher.
   The size is estimated with high confidence to be 1 row (25 bytes).
   The estimated time for this step is 0.01 seconds.
8) We do an all-AMPs JOIN step from OPTBASE_PCTDB.t1 by way of a
   RowHash match scan with a condition of ("OPTBASE_PCTDB.t1.a1 <
   :%SSQ20"), which is joined to OPTBASE_PCTDB.t2 by way of a RowHash
   match scan with no residual conditions. OPTBASE_PCTDB.t1 and
   OPTBASE_PCTDB.t2 are joined using a sliding-window merge join,
   with a join condition of ("OPTBASE_PCTDB.t1.a1 =
   OPTBASE_PCTDB.t2.a2"). The input tables OPTBASE_PCTDB.t1 and
   OPTBASE_PCTDB.t2 will not be cached in memory, but
   OPTBASE_PCTDB.t1 is eligible for synchronized scanning. The
   result goes into Spool 5 (group_amps), which is built locally on
   the AMPs. The size of Spool 5 is estimated with no confidence to
   be 33,333,334 rows (2,166,666,710 bytes). The estimated time for
   this step is 1 minute and 10 seconds.
...

USINGリクエスト修飾子が先行するIPEに適格なリクエストのDYNAMIC EXPLAIN

この例で説明されているリクエストは、USINGリクエスト修飾子が先行しているためIPEに不適格です。そのため、このDYNAMIC EXPLAINリクエストは、リクエストの静的計画を返します。

DYNAMIC EXPLAIN
USING (x INTEGER)
SELECT *
FROM t1, t2
WHERE t1.a1 < (SELECT MAX(t3.a3)
               FROM t3)
AND t1.a1 = t2.a2
AND t1.a1 = :x;
Explanation
-----------------------------------------------------------------------
This request is eligible for incremental planning and execution (IPE) but dynamic plan does not support USING request modifier. The following is the static plan for the request. 
...
3) We do an all-AMPs SUM step to aggregate from OPTBASE_PCTDB.t3 by
   way of an all-rows scan with no residual conditions. Aggregate
   Intermediate Results are computed globally, then placed in Spool 3.
   The size of Spool 3 is estimated with high confidence to be 1 row
   (19 bytes). The estimated time for this step is 0.05 seconds.
4) We do an all-AMPs RETRIEVE step from Spool 3 (Last Use) by way of
   an all-rows scan into Spool 1 (all_amps), which is built locally
   on the AMPs. The size of Spool 1 is estimated with high
   confidence to be 1 row (25 bytes). The estimated time for this
   step is 0.02 seconds.
5) We do an all-AMPs DISPATCHER RETRIEVE step from Spool 1 (Last Use)
   by way of an all-rows scan and send the rows back to the
   Dispatcher. The size is estimated with high confidence to be 1
   row. The estimated time for this step is 0.02 seconds.
6) We do a single-AMP JOIN step from OPTBASE_PCTDB.t2 by way of the
   unique primary index "OPTBASE_PCTDB.t2.a2 = :x", which is joined
   to OPTBASE_PCTDB.t1 by way of the unique primary index
   "OPTBASE_PCTDB.t1.a1 = :x" with a residual condition of (
   "(OPTBASE_PCTDB.t1.a1 < :%SSQ21) AND (OPTBASE_PCTDB.t1.a1 = :x)").
   OPTBASE_PCTDB.t2 and OPTBASE_PCTDB.t1 are joined using a merge
   join, with a join condition of ("OPTBASE_PCTDB.t1.a1 =
   OPTBASE_PCTDB.t2.a2"). The result goes into Spool 5 (one-amp),
   which is built locally on that AMP. The size of Spool 5 is
   estimated with high confidence to be 1 row (87 bytes). The
   estimated time for this step is 0.02 seconds.
...

リクエストがIPEに不適格な場合のDYNAMIC EXPLAIN

この例で説明されているリクエストは、単一行アクセスまたはスカラーsubquery操作を何も指定しないため、IPEに対して適格ではありません。リクエストの静的計画が表示されます。

EXPLAINテキスト レポートは、IPEが無効な場合のレポートと変更ありません。

DYNAMIC EXPLAIN 
SELECT *
FROM t1
WHERE a3 > 10;
Explanation
-----------------------------------------------------------------------
...
3) We do an all-AMPs RETRIEVE step from OPTBASE_PCTDB.t1 by way of an
   all-rows scan with a condition of ("OPTBASE_PCTDB.t1.a3 > 10") into
   Spool 1 (all_amps), which is built locally on the AMPs. The size of
   Spool 1 is estimated with no confidence to be 1 row (54 bytes). The
   estimated time for this step is 0.03 seconds.
...

リクエストが増分計画および実行に適格なもののしきい値を満たさない場合のDYNAMIC EXPLAIN

この例では、説明されているリクエストがIPEに適格なものの、実行コスト用のシステム判別の特定のしきい値を満たさない場合のEXPLAINレポートについて示します。

IPEに関するシステム判別のしきい値が満たされていないので、Vantageは、リクエストの動的計画ではなく静的計画を表示します。

DYNAMIC EXPLAIN 
SELECT *
FROM t1, t2
WHERE t1.a1 < (SELECT MAX(t3.a3)
               FROM t3)
AND   t1.a1 = t2.a2;
Explanation
----------------------------------------------------------------------
This request is eligible for incremental planning and execution (IPE) but does not meet thresholds. The following is the static plan for the request. 
...
5) We do an all-AMPs SUM step to aggregate from OPTBASE_PCTDB.t3 by
   way of an all-rows scan with no residual conditions. Aggregate
   Intermediate Results are computed globally, then placed in Spool 3.
   The size of Spool 3 is estimated with high confidence to be 1 row
   (19 bytes). The estimated time for this step is 0.02 seconds.
6) We do an all-AMPs RETRIEVE step from Spool 3 (Last Use) by way of
   an all-rows scan into Spool 1 (all_amps), which is built locally
   on the AMPs. The size of Spool 1 is estimated with high
   confidence to be 1 row (25 bytes). The estimated time for this
   step is 0.00 seconds.
7) We do an all-AMPs DISPATCHER RETRIEVE step from Spool 1 (Last Use)
   by way of an all-rows scan and send the rows back to the
   Dispatcher. The size is estimated with high confidence to be 1
   row. The estimated time for this step is 0.02 seconds.
8) We do an all-AMPs JOIN step from OPTBASE_PCTDB.t2 by way of a
   RowHash match scan, which is joined to OPTBASE_PCTDB.t1 by way of
   a RowHash match scan with a condition of ("OPTBASE_PCTDB.t1.a1 <
   :%SSQ20"). OPTBASE_PCTDB.t2 and OPTBASE_PCTDB.t1 are joined using
   a merge join, with a join condition of ("OPTBASE_PCTDB.t1.a1 =
   OPTBASE_PCTDB.t2.a2"). The result goes into Spool 5 (group_amps),
   which is built locally on the AMPs. The size of Spool 5 is
   estimated with no confidence to be 4 rows (260 bytes). The
   estimated time for this step is 0.02 seconds.
...

リクエストがIPEに適格なもののIPEが無効な場合のDYNAMIC EXPLAIN

IPEに適格なリクエストのDYNAMIC EXPLAINを実行依頼するものの、システムでIPEが無効な場合、Vantageはリクエストの静的プランを表示します。次の例で太字で強調表示されているEXPLAINテキストの最初の文では、リクエストがIPEに適格なもののIPEが無効であることが説明されています。

DYNAMIC EXPLAIN
SELECT *
FROM t1, t2
WHERE t1.a1 < (SELECT MAX(t3.a3)
               FROM t3)
AND   t1.a1 = t2.a2;
Explanation
----------------------------------------------------------------------
This request is eligible for incremental planning and execution (IPE). IPE is disabled. The following is the static plan for the request. 
...
5) We do an all-AMPs SUM step to aggregate from OPTBASE_PCTDB.t3 by
   way of an all-rows scan with no residual conditions. Aggregate
   Intermediate Results are computed globally, then placed in Spool 3.
   The size of Spool 3 is estimated with high confidence to be 1 row
   (19 bytes). The estimated time for this step is 0.02 seconds.
6) We do an all-AMPs RETRIEVE step from Spool 3 (Last Use) by way of
   an all-rows scan into Spool 1 (all_amps), which is built locally
   on the AMPs. The size of Spool 1 is estimated with high
   confidence to be 1 row (25 bytes). The estimated time for this
   step is 0.00 seconds.
7) We do an all-AMPs DISPATCHER RETRIEVE step from Spool 1 (Last Use)
   by way of an all-rows scan and send the rows back to the
   Dispatcher. The size is estimated with high confidence to be 1
   row. The estimated time for this step is 0.02 seconds.
8) We do an all-AMPs JOIN step from OPTBASE_PCTDB.t2 by way of a
   RowHash match scan, which is joined to OPTBASE_PCTDB.t1 by way of
   a RowHash match scan with a condition of ("OPTBASE_PCTDB.t1.a1 <
   :%SSQ20"). OPTBASE_PCTDB.t2 and OPTBASE_PCTDB.t1 are joined using
   a merge join, with a join condition of ("OPTBASE_PCTDB.t1.a1 =
   OPTBASE_PCTDB.t2.a2"). The result goes into Spool 5 (group_amps),
   which is built locally on the AMPs. The size of Spool 5 is
   estimated with no confidence to be 4 rows (260 bytes). The
   estimated time for this step is 0.02 seconds.
...