GET_QUERY_OPERATOR_STATS¶
完了したクエリ内の個別のクエリ演算子に関する統計を返します。この関数は、過去14日間に実行された任意の完了したクエリに対して実行できます。
You can use this information to understand the structure of a query and identify query operators --- for example, the join operator --- that cause performance problems.
For example, you can use this information to determine which operators are consuming the most resources. As another example, you can use this function to identify joins that have more output rows than input rows, which can be a sign of an "exploding" join; for example, an unintended Cartesian product.
これらの統計は、 Snowsight の クエリプロファイル タブでも利用できます。GET_QUERY_OPERATOR_STATS() 関数は、同じ情報をプログラムによるインターフェイス経由で利用できるようにします。
問題のあるクエリ演算子を見つける方法の詳細については、 クエリプロファイルによって特定される一般的なクエリの問題 をご参照ください。
構文¶
GET_QUERY_OPERATOR_STATS( <query_id> )
引数¶
query_idクエリの ID。次を使用できます。
文字列リテラル(一重引用符で囲まれた文字列)。
クエリ ID を含む セッション変数。
LAST_QUERY_ID 関数の呼び出しからの戻り値。
戻り値¶
GET_QUERY_OPERATOR_STATS 関数は テーブル関数。クエリ内の各クエリ演算子に関する統計を含む行を返します。詳細については、以下の 出力 と 使用上の注意 セクションをご参照ください。
使用上の注意¶
This function returns statistics only for queries that have completed.
クエリを実行したウェアハウスに対する OPERATE または MONITOR の権限が必要です。
This function provides detailed statistics about each query operator used in the specified query. The following list shows the possible query operators:
Aggregate: 入力をグループ化し、集計関数を計算します。
CartesianJoin: 特殊な結合の型。
Delete: テーブルから記録を削除します。
ExternalFunction: 外部関数による処理を表します。
ExternalScan: ステージオブジェクトに保存されているデータへのアクセスを表します。
Filter: 記録をフィルターする操作を表します。
Flatten: VARIANT 記録を処理し、場合によっては指定されたパスでそれらをフラット化します。
Generator: Generates records by using the TABLE(GENERATOR(...)) construct.
GroupingSets: Represents constructs, such as GROUPING SETS, ROLLUP, and CUBE.
Insert: INSERT または COPY 操作のいずれかにより、テーブルに記録を追加します。
InternalObject: Represents access to an internal data object; for example, in an Information Schema or the result of a previous query.
Join: 特定の条件で2つの入力を結合します。
JoinFilter: クエリプランでさらに結合の条件に一致しない可能性があると識別できるタプルを削除する特別なフィルタリング操作。
Merge: テーブルで MERGE 操作を実行します。
Pivot: 列の一意の値を複数の列に変換し、必要な集計を実行します。
Result: クエリ結果を返します。
Sort: 特定の式の入力を順序付けます。
SortWithLimit: ソート後に入力シーケンスの一部、通常は
ORDER BY ... LIMIT ... OFFSET ...構築の結果を生成します。TableScan: 単一のテーブルへのアクセスを表します。
UnionAll:2つの入力を連結します。
Unload: ステージ内のテーブルからファイルにデータをエクスポートする COPY 操作を表します。
Unpivot: 列を行に変換することにより、テーブルを回転します。
Update: テーブル内の記録を更新します。
ValuesClause: VALUES 句で提供される値のリスト。
WindowFunction: ウィンドウ関数を計算します。
WithClause: SELECT ステートメントの本文より優先され、1つ以上の CTEs を定義します。
WithReference: WITH 句のインスタンス。
情報はテーブルとして返されます。テーブルの各行は、1つの演算子に対応します。行には、その演算子の実行の内訳とクエリ統計が含まれます。
行には、 演算子の属性 もリストされる場合があります(これらは演算子の型によって異なります)。
Statistics that break down query execution time are expressed as a percentage of the total query execution time.
特定の統計の詳細については、 出力 (このトピック内)をご参照ください。
この関数はテーブル関数であるため、 FROM 句で使用し、
TABLE()でラップする必要があります。例:SELECT * FROM TABLE(GET_QUERY_OPERATOR_STATS(last_query_id()));
特定のクエリ(つまり、特定の UUID)の個別な実行に対してこの関数は決定論的です。毎回同じ値を返します。
ただし、同じクエリテキストを別の方法で実行すると、この関数は別のランタイム統計を返す可能性があります。統計は多くの要因に依存します。次の要因は、実行に大きな影響を与える可能性があるため、この関数によって返される統計にも大きな影響を与える可能性があります。
データの量。
マテリアライズドビュー の可用性と、それらのマテリアライズドビューが最後に更新されてからのデータへの変更(ある場合)。
クラスタリング の有無。
以前にキャッシュされたデータの有無。
仮想ウェアハウスのサイズ。
値は、ユーザーのクエリやデータ以外の要因によっても影響を受ける可能性があります。通常、これらの要因が及ぼす影響は大きくありません。次の要因が含まれます。
仮想ウェアハウスの初期化時間。
外部関数の待機時間。
出力¶
この関数は、次の列を返します。
Column name |
Data type |
説明 |
|---|---|---|
QUERY_ID |
VARCHAR |
SQL ステートメントのための内部、システム生成識別子であるクエリ ID。 |
STEP_ID |
NUMBER(38, 0) |
クエリプラン内のステップの識別子。 |
OPERATOR_ID |
NUMBER(38, 0) |
演算子の識別子。これはクエリ内で一意です。値は0から始まります。 |
PARENT_OPERATORS |
1つ以上の NUMBER(38, 0)を含む ARRAY |
この演算子の親演算子の識別子。これがクエリプランの最後の演算子(通常は結果演算子)の場合は NULL。 |
OPERATOR_TYPE |
VARCHAR |
The type of query operator; for example, |
OBJECT を含む VARIANT |
Statistics about the operator (for example, the number of output rows from the operator). |
|
OBJECT を含む VARIANT |
演算子の実行時間に関する情報。 |
|
OBJECT を含む VARIANT |
Information about the operator. This information depends on the operator type. |
演算子の特定の列に関する情報がない場合、値は NULL です。
Three of these columns contain OBJECTs. Each object contains key/value pairs. The tables below describe the keys in these objects.
OPERATOR_STATISTICS¶
OPERATOR_STATISTICS 列の OBJECTs にあるフィールドは、演算子に関する追加情報を提供します。情報には次が含まれます。
キー |
Nested key (if applicable) |
Data type |
説明 |
|---|---|---|---|
|
Statistics for Data Manipulation Language (DML) queries. |
||
|
DOUBLE |
Number of rows inserted into a table or tables. |
|
|
DOUBLE |
Number of rows updated in a table. |
|
|
DOUBLE |
Number of rows deleted from a table. |
|
|
DOUBLE |
Number of rows unloaded during data export. |
|
|
Information about calls to extension functions. If the value of a field is zero, then the field is not displayed. |
||
|
DOUBLE |
Amount of time for the Java UDF handler to load. |
|
|
DOUBLE |
Number of times the Java UDF handler is invoked. |
|
|
DOUBLE |
Maximum amount of time for the Java UDF handler to execute. |
|
|
DOUBLE |
Average amount of time to execute the Java UDF handler. |
|
|
DOUBLE |
Number of times the Java UDTF process method was invoked. |
|
|
DOUBLE |
Amount of time to execute the Java UDTF process. |
|
|
DOUBLE |
Average amount of time to execute the Java UDTF process. |
|
|
DOUBLE |
Number of times the Java UDTF constructor was invoked. |
|
|
DOUBLE |
Amount of time to execute the Java UDTF constructor. |
|
|
DOUBLE |
Average amount of time to execute the Java UDTF constructor. |
|
|
DOUBLE |
Number of times the Java UDTF endPartition method was invoked. |
|
|
DOUBLE |
Amount of time to execute the Java UDTF endPartition method. |
|
|
DOUBLE |
Average amount of time to execute the Java UDTF |
|
|
DOUBLE |
Maximum amount of time to download the Java UDF dependencies. |
|
|
DOUBLE |
Peak memory usage as reported by the JVM. |
|
|
DOUBLE |
Compile time for the Java UDF inline code. |
|
|
DOUBLE |
Number of times the Python UDF handler was invoked. |
|
|
DOUBLE |
Total execution time for the Python UDF handler. |
|
|
DOUBLE |
Average amount of time to execute the Python UDF handler. |
|
|
DOUBLE |
Peak memory usage by the Python sandbox environment. |
|
|
DOUBLE |
Average amount of time to create the Python environment, including downloading and installing packages. |
|
|
DOUBLE |
Amount of time to run the Conda solver to solve Python packages. |
|
|
DOUBLE |
Amount of time to create the Python environment. |
|
|
DOUBLE |
Amount of time to initialize the Python UDF. |
|
|
DOUBLE |
Number of external file bytes read for UDFs. |
|
|
DOUBLE |
Number of external files accessed for UDFs. |
|
|
Information about calls to external functions. If the value of a field --- for example
|
||
|
DOUBLE |
Number of times that an external function was called. This number can be different from the number of external function calls in the text of the SQL statement because of the number of batches that rows are divided into, the number of retries if there are transient network problems, and so on. |
|
|
DOUBLE |
Number of rows sent to external functions. |
|
|
DOUBLE |
Number of rows received back from external functions. |
|
|
DOUBLE |
Number of bytes sent to external functions. If the key includes |
|
|
DOUBLE |
Number of bytes received from external functions. If the key includes |
|
|
DOUBLE |
Number of retries because of transient errors. |
|
|
DOUBLE |
Average amount of time per invocation (call) in milliseconds between the time Snowflake sent the data and received the returned data. |
|
|
INTEGER |
4xxステータスコードを返した HTTP リクエストの合計数。 |
|
|
INTEGER |
5xxステータスコードを返した HTTP リクエストの合計数。 |
|
|
DOUBLE |
HTTP リクエストに成功した場合の平均遅延時間。 |
|
|
DOUBLE |
Average overhead per successful request because of a slowdown caused by throttling (HTTP 429). |
|
|
DOUBLE |
Number of batches that were retried because of HTTP 429 errors. |
|
|
DOUBLE |
成功した HTTP リクエストの50パーセンタイルの遅延。成功したすべてのリクエストの50%で、完了までにかかった時間がこの時間未満。 |
|
|
DOUBLE |
成功した HTTP リクエストの90パーセンタイルの遅延。成功したすべてのリクエストの90%で、完了までにかかった時間がこの時間未満。 |
|
|
DOUBLE |
成功した HTTP リクエストの95パーセンタイルの遅延。成功したすべてのリクエストの95%で、完了までにかかった時間がこの時間未満。 |
|
|
DOUBLE |
成功した HTTP リクエストの99パーセンタイルの遅延。成功したすべてのリクエストの99%で、完了までにかかった時間がこの時間未満。 |
|
|
INTEGER |
Number of input rows. This can be missing for an operator with no input edges from other operators. |
|
|
クエリ中に実行されるI/O(入出力)操作に関する情報。 |
||
|
DOUBLE |
Percentage of data scanned for a given table so far. |
|
|
DOUBLE |
Number of bytes scanned so far. |
|
|
DOUBLE |
Percentage of data scanned from the local disk cache. |
|
|
DOUBLE |
Bytes written; for example, when loading into a table. |
|
|
DOUBLE |
結果オブジェクトに書き込まれるバイト数。 For example, 一般に、結果オブジェクトは、なんであれクエリの結果として生成されるものを表し、 |
|
|
DOUBLE |
結果オブジェクトから読み取ったバイト数。 |
|
|
DOUBLE |
Bytes read from an external object; for example, a stage. |
|
|
|
DOUBLE |
Amount of data sent over the network. |
|
INTEGER |
Number of output rows. This can be missing for the operator that returns the results to the user; which is usually the RESULT operator. |
|
|
テーブルのプルーニングに関する情報。 |
||
|
DOUBLE |
Number of partitions pruned by Snowflake Optima. |
|
|
DOUBLE |
Number of partitions scanned so far. |
|
|
DOUBLE |
Total number of partitions in a given table. |
|
|
中間結果がメモリに収まらない操作のディスク使用量に関する情報。 |
||
|
DOUBLE |
Volume of data spilled to remote disk. |
|
|
DOUBLE |
Volume of data spilled to local disk. |
|
|
検索最適化サービス を使用するクエリに関する情報。 |
||
|
DOUBLE |
Number of partitions pruned by search optimization. |
|
|
DOUBLE |
検索最適化およびSnowflake Optimaによって排除されたパーティションの数。 |
EXECUTION_TIME_BREAKDOWN¶
EXECUTION_TIME_BREAKDOWN 列の OBJECTs にあるフィールドを以下に示します。
キー |
Data type |
説明 |
|---|---|---|
|
DOUBLE |
Percentage of the total query time spent by this operator. |
|
DOUBLE |
クエリ処理の設定にかかった時間。 |
|
DOUBLE |
CPU によるデータの処理にかかった時間。 |
|
DOUBLE |
関与しているプロセス間のアクティビティの同期に費やされた時間。 |
|
DOUBLE |
ローカルディスクアクセスの待機中に処理がブロックされた時間。 |
|
DOUBLE |
リモートディスクアクセスの待機中に処理がブロックされた時間。 |
|
DOUBLE |
処理がネットワークデータ転送を待機していた時間。 |
OPERATOR_ATTRIBUTES¶
Each output row describes one operator in the query. The following table shows the possible types of operators; for example, the Filter operator. For each type of operator, the table shows the possible attributes; for example, the expression used to filter the rows.
演算子の属性は、 VARIANT 型で OBJECT を含む OPERATOR_ATTRIBUTES 列に格納されます。OBJECT にはキーと値のペアが含まれています。各キーは、演算子の属性1つに対応します。
Operator name |
キー |
Data type |
説明 |
|---|---|---|---|
|
|||
|
VARCHAR の ARRAY |
コンピューティングされた関数のリスト。 |
|
|
VARCHAR の ARRAY |
Group-by expression. |
|
|
|||
|
VARCHAR |
非等価結合式。 |
|
|
VARCHAR |
等値結合式。 |
|
|
VARCHAR |
結合の型(INNER)。 |
|
|
|
VARCHAR |
更新されたテーブルの名前。 |
|
|||
|
VARCHAR |
データが読み取られるステージの名前。 |
|
|
VARCHAR |
ステージのタイプ。 |
|
|
|
VARCHAR |
データのフィルターに使用される式。 |
|
|
VARCHAR |
Input expression used to flatten data. |
|
|||
|
NUMBER |
入力パラメーター ROWCOUNT の値。 |
|
|
NUMBER |
入力パラメーター TIMELIMIT の値。 |
|
|
|||
|
VARCHAR の ARRAY |
コンピューティングされた関数のリスト。 |
|
|
VARCHAR の ARRAY |
グループ化セットのリスト。 |
|
|
|||
|
VARCHAR |
挿入される式。 |
|
|
VARCHAR の ARRAY |
記録が追加されるテーブル名のリスト。 |
|
|
|
VARCHAR |
Name of the accessed object. |
|
|||
|
VARCHAR |
非等価結合式。 |
|
|
VARCHAR |
等値結合式。 |
|
|
VARCHAR |
結合の型(INNER、 OUTER、 LEFT、 JOIN など) |
|
|
|
NUMBER |
Operator id of the join used to identify tuples that can be filtered out. |
|
|
VARCHAR |
更新されたテーブルの名前。 |
|
|||
|
VARCHAR の ARRAY |
結果が集計される残りの列。 |
|
|
VARCHAR の ARRAY |
ピボット値の結果の列。 |
|
|
|
VARCHAR の ARRAY |
生成された式。 |
|
|
VARCHAR の ARRAY |
ソート順を定義する式。 |
|
|||
|
NUMBER |
生成されたタプルが発行される順序付けられたシーケンス内の位置。 |
|
|
NUMBER |
生成された行の数。 |
|
|
VARCHAR の ARRAY |
ソート順を定義する式。 |
|
|
|||
|
VARCHAR の ARRAY |
スキャンされた列のリスト |
|
|
VARCHAR の ARRAY |
バリアント列から抽出されたパスのリスト。 |
|
|
VARCHAR |
アクセスされているテーブルのエイリアス。 |
|
|
VARCHAR |
アクセスされているテーブルの名前。 |
|
|
|
VARCHAR |
データが保存されるステージ。 |
|
|
VARCHAR の ARRAY |
ピボット解除クエリの出力列。 |
|
|
VARCHAR |
更新されたテーブルの名前。 |
|
|||
|
NUMBER |
生成された値の数。 |
|
|
VARCHAR |
値のリスト。 |
|
|
|
VARCHAR の ARRAY |
コンピューティングされた関数のリスト。 |
|
|
VARCHAR |
WITH 句のエイリアス。 |
演算子がリストされていない場合は、属性が生成されず、値は {} として報告されます。
注釈
The following operators do not have any operator attributes and therefore are not included in the table of
OPERATOR_ATTRIBUTES:UnionAllExternalFunction
例¶
以下の例では、GET_QUERY_OPERATOR_STATS関数を呼びだしています。
単一のクエリに関するデータの取得¶
この例は、2つの小さなテーブルを結合する SELECT の統計を示しています。
SELECT ステートメントを実行します。
SELECT x1.i, x2.i
FROM x1 INNER JOIN x2 ON x2.i = x1.i
ORDER BY x1.i, x2.i;
クエリ ID を取得します。
SET lqid = (SELECT LAST_QUERY_ID());
GET_QUERY_OPERATOR_STATS() を呼び出して、クエリ内の個々のクエリ演算子に関する統計を取得します。
SELECT * FROM TABLE(GET_QUERY_OPERATOR_STATS($lqid));
+--------------------------------------+---------+-------------+--------------------+---------------+-----------------------------------------+-----------------------------------------------+----------------------------------------------------------------------+
| QUERY_ID | STEP_ID | OPERATOR_ID | PARENT_OPERATORS | OPERATOR_TYPE | OPERATOR_STATISTICS | EXECUTION_TIME_BREAKDOWN | OPERATOR_ATTRIBUTES |
|--------------------------------------+---------+-------------+--------------------+---------------+-----------------------------------------+-----------------------------------------------+----------------------------------------------------------------------|
| 01a8f330-0507-3f5b-0000-43830248e09a | 1 | 0 | NULL | Result | { | { | { |
| | | | | | "input_rows": 64 | "overall_percentage": 0.000000000000000e+00 | "expressions": [ |
| | | | | | } | } | "X1.I", |
| | | | | | | | "X2.I" |
| | | | | | | | ] |
| | | | | | | | } |
| 01a8f330-0507-3f5b-0000-43830248e09a | 1 | 1 | [ 0 ] | Sort | { | { | { |
| | | | | | "input_rows": 64, | "overall_percentage": 0.000000000000000e+00 | "sort_keys": [ |
| | | | | | "output_rows": 64 | } | "X1.I ASC NULLS LAST", |
| | | | | | } | | "X2.I ASC NULLS LAST" |
| | | | | | | | ] |
| | | | | | | | } |
| 01a8f330-0507-3f5b-0000-43830248e09a | 1 | 2 | [ 1 ] | Join | { | { | { |
| | | | | | "input_rows": 128, | "overall_percentage": 0.000000000000000e+00 | "equality_join_condition": "(X2.I = X1.I)", |
| | | | | | "output_rows": 64 | } | "join_type": "INNER" |
| | | | | | } | | } |
| 01a8f330-0507-3f5b-0000-43830248e09a | 1 | 3 | [ 2 ] | TableScan | { | { | { |
| | | | | | "io": { | "overall_percentage": 0.000000000000000e+00 | "columns": [ |
| | | | | | "bytes_scanned": 1024, | } | "I" |
| | | | | | "percentage_scanned_from_cache": 1, | | ], |
| | | | | | "scan_progress": 1 | | "table_name": "MY_DB.MY_SCHEMA.X2" |
| | | | | | }, | | } |
| | | | | | "output_rows": 64, | | |
| | | | | | "pruning": { | | |
| | | | | | "partitions_scanned": 1, | | |
| | | | | | "partitions_total": 1 | | |
| | | | | | } | | |
| | | | | | } | | |
| 01a8f330-0507-3f5b-0000-43830248e09a | 1 | 4 | [ 2 ] | JoinFilter | { | { | { |
| | | | | | "input_rows": 64, | "overall_percentage": 0.000000000000000e+00 | "join_id": "2" |
| | | | | | "output_rows": 64 | } | } |
| | | | | | } | | |
| 01a8f330-0507-3f5b-0000-43830248e09a | 1 | 5 | [ 4 ] | TableScan | { | { | { |
| | | | | | "io": { | "overall_percentage": 0.000000000000000e+00 | "columns": [ |
| | | | | | "bytes_scanned": 1024, | } | "I" |
| | | | | | "percentage_scanned_from_cache": 1, | | ], |
| | | | | | "scan_progress": 1 | | "table_name": "MY_DB.MY_SCHEMA.X1" |
| | | | | | }, | | } |
| | | | | | "output_rows": 64, | | |
| | | | | | "pruning": { | | |
| | | | | | "partitions_scanned": 1, | | |
| | | | | | "partitions_total": 1 | | |
| | | | | | } | | |
| | | | | | } | | |
+--------------------------------------+---------+-------------+--------------------+---------------+-----------------------------------------+-----------------------------------------------+----------------------------------------------------------------------+
「爆発」結合演算子の特定¶
次の例は、 GET_QUERY_OPERATOR_STATS を使用して複雑なクエリを調べる方法を示しています。この例では、その演算子に入力されたよりも多くの行を生成するクエリ内の演算子を検索します。
分析するクエリは次のとおりです。
SELECT *
FROM t1
JOIN t2 ON t1.a = t2.a
JOIN t3 ON t1.b = t3.b
JOIN t4 ON t1.c = t4.c;
以前のクエリのクエリ ID を取得します。
SET lid = LAST_QUERY_ID();
The following query shows the ratio of output rows to input rows for each of the join operators in the query:
SELECT operator_id,
operator_attributes,
operator_statistics:output_rows / operator_statistics:input_rows AS row_multiple
FROM TABLE(GET_QUERY_OPERATOR_STATS($lid))
WHERE operator_type = 'Join'
ORDER BY step_id, operator_id;
+---------+-------------+--------------------------------------------------------------------------+---------------+
| STEP_ID | OPERATOR_ID | OPERATOR_ATTRIBUTES | ROW_MULTIPLE |
+---------+-------------+--------------------------------------------------------------------------+---------------+
| 1 | 1 | { "equality_join_condition": "(T4.C = T1.C)", "join_type": "INNER" } | 49.969249692 |
| 1 | 3 | { "equality_join_condition": "(T3.B = T1.B)", "join_type": "INNER" } | 116.071428571 |
| 1 | 5 | { "equality_join_condition": "(T2.A = T1.A)", "join_type": "INNER" } | 12.20657277 |
+---------+-------------+--------------------------------------------------------------------------+---------------+
爆発結合を特定した後、各結合条件を調べて、条件が正しいことを確認できます。