diff --git a/docs-2.0/3.ngql-guide/17.query-tuning-statements/1.explain-and-profile.md b/docs-2.0/3.ngql-guide/17.query-tuning-statements/1.explain-and-profile.md index 46955bf8f65..4b90184f580 100644 --- a/docs-2.0/3.ngql-guide/17.query-tuning-statements/1.explain-and-profile.md +++ b/docs-2.0/3.ngql-guide/17.query-tuning-statements/1.explain-and-profile.md @@ -1,97 +1,99 @@ # EXPLAIN and PROFILE -`EXPLAIN` helps output the execution plan of an nGQL statement without executing the statement. `PROFILE` executes the statement, then outputs the execution plan as well as the execution profile. You can optimize the queries for better performance with the execution plan and profile. +`EXPLAIN` helps output the execution plan of an nGQL statement without executing the statement. + +`PROFILE` executes the statement, then outputs the execution plan as well as the execution profile. You can optimize the queries for better performance according to the execution plan and profile. ## Execution Plan The execution plan is determined by the execution planner in the Nebula Graph query engine. -The execution planner processes the parsed nGQL statements into actions. An action is the smallest unit that can be executed. A typical action fetches all neighbors of a given vertex, gets the properties of an edge, or filters vertices or edges based on the given conditions. Each action is assigned to an operator that performs the action. +The execution planner processes the parsed nGQL statements into `actions`. An `action` is the smallest unit that can be executed. A typical `action` fetches all neighbors of a given vertex, gets the properties of an edge, and filters vertices or edges based on the given conditions. Each `action` is assigned to an `operator` that performs the action. -For example, a `SHOW TAGS` statement is processed into two actions and assigned to a `Start` operator and a `ShowTags` operator, while a more complex `GO` statement may be processed into more than 10 actions and assigned to 10 operators. +For example, a `SHOW TAGS` statement is processed into two `actions` and assigned to a `Start operator` and a `ShowTags operator`, while a more complex `GO` statement may be processed into more than 10 `actions` and assigned to 10 operators. ## Syntax * `EXPLAIN` -```ngql -EXPLAIN [format="row" | "dot"] -``` + ```ngql + EXPLAIN [format="row" | "dot"] ; + ``` * `PROFILE` -```ngql -PROFILE [format="row" | "dot"] -``` + ```ngql + PROFILE [format="row" | "dot"] ; + ``` ## Output formats -The output of an `EXPLAIN` or a `PROFILE` statement has two formats, the default "row" format and the "dot" format. You can use the `format` option to modify the output format. Omitting the `format` option indicates using the default "row" format. - -## Format "row" - -The "row" format outputs the return message in a table as follows. - -* `EXPLAIN`: - - ```ngql - nebula> EXPLAIN format="row" SHOW TAGS; - Execution succeeded (time spent 104/705 us) - Execution Plan - +----+----------+--------------+----------------+-----------------------------------------------------------------------+ - | id | name | dependencies | profiling data | operator info | - +----+----------+--------------+----------------+-----------------------------------------------------------------------+ - | 0 | ShowTags | 2 | | outputVar: [ {"colNames":[],"name":"__ShowTags_0","type":"DATASET"}] | - | | | | | inputVar: | - +----+----------+--------------+----------------+-----------------------------------------------------------------------+ - | 2 | Start | | | outputVar: [ {"colNames":[],"name":"__Start_2","type":"DATASET"}] | - +----+----------+--------------+----------------+-----------------------------------------------------------------------+ - ``` - -* `PROFILE`: - - ```ngql - nebula> PROFILE format="row" SHOW TAGS; - +--------+ - | Name | - +--------+ - | player | - +--------+ - | team | - +--------+ - Got 2 rows (time spent 2038/2728 us) - - Execution Plan - - +----+----------+--------------+----------------------------------------------------+---------------------------------------------------------------------+ - | id | name | dependencies | profiling data | operator info | - +----+----------+--------------+----------------------------------------------------+---------------------------------------------------------------------+ - | 0 | ShowTags | 2 | ver: 0, rows: 1, execTime: 79us, totalTime: 1692us | outputVar: [{"colNames":[],"name":"__ShowTags_0","type":"DATASET"}] | - | | | | | inputVar: | - +----+----------+--------------+----------------------------------------------------+---------------------------------------------------------------------+ - | 2 | Start | | ver: 0, rows: 0, execTime: 1us, totalTime: 57us | outputVar: [{"colNames":[],"name":"__Start_2","type":"DATASET"}] | - +----+----------+--------------+----------------------------------------------------+---------------------------------------------------------------------+ - ``` - -The descriptions of the columns are as follows: - -|Column|Description| +The output of an `EXPLAIN` or a `PROFILE` statement has two formats, the default `row` format and the `dot` format. You can use the `format` option to modify the output format. Omitting the `format` option indicates using the default `row` format. + +## The `row` format + +The `row` format outputs the return message in a table as follows. + +* `EXPLAIN` + + ```ngql + nebula> EXPLAIN format="row" SHOW TAGS; + Execution succeeded (time spent 327/892 us) + + Execution Plan + + -----+----------+--------------+----------------+---------------------------------------------------------------------- + | id | name | dependencies | profiling data | operator info | + -----+----------+--------------+----------------+---------------------------------------------------------------------- + | 1 | ShowTags | 0 | | outputVar: [{"colNames":[],"name":"__ShowTags_1","type":"DATASET"}] | + | | | | | inputVar: | + -----+----------+--------------+----------------+---------------------------------------------------------------------- + | 0 | Start | | | outputVar: [{"colNames":[],"name":"__Start_0","type":"DATASET"}] | + -----+----------+--------------+----------------+---------------------------------------------------------------------- + ``` + +* `PROFILE` + + ```ngql + nebula> PROFILE format="row" SHOW TAGS; + +--------+ + | Name | + +--------+ + | player | + +--------+ + | team | + +--------+ + Got 2 rows (time spent 2038/2728 us) + + Execution Plan + + -----+----------+--------------+----------------------------------------------------+---------------------------------------------------------------------- + | id | name | dependencies | profiling data | operator info | + -----+----------+--------------+----------------------------------------------------+---------------------------------------------------------------------- + | 1 | ShowTags | 0 | ver: 0, rows: 1, execTime: 42us, totalTime: 1177us | outputVar: [{"colNames":[],"name":"__ShowTags_1","type":"DATASET"}] | + | | | | | inputVar: | + -----+----------+--------------+----------------------------------------------------+---------------------------------------------------------------------- + | 0 | Start | | ver: 0, rows: 0, execTime: 1us, totalTime: 57us | outputVar: [{"colNames":[],"name":"__Start_0","type":"DATASET"}] | + -----+----------+--------------+----------------------------------------------------+---------------------------------------------------------------------- + ``` + +The descriptions are as follows. + +|Parameter|Description| |-|-| -|`id`|Indicates the ID of the operator.| -|`name`|Indicates the name of the operator.| -|`dependencies`|Shows the ID of the operator that the current operator depends on.| -|`profiling data`|Shows the execution profile. `ver` is the version of the operator, which you can use to identify loops; `rows` shows the number of rows to be output by the operator; `execTime` shows the execution time only; `totalTime` contains the execution time and the system scheduling and queueing time.| -|`operator info`|Shows the detailed information of the operator.| +|`id`|The ID of the `operator`.| +|`name`|The name of the `operator`.| +|`dependencies`|The ID of the `operator` that the current `operator` depends on.| +|`profiling data`|The content of the execution profile. `ver` is the version of the `operator`. `rows` shows the number of rows to be output by the `operator`. `execTime` shows the execution time of `action`. `totalTime` is the sum of the execution time, the system scheduling time, and the queueing time.| +|`operator info`|The detailed information of the `operator`.| -## Format "dot" +## The `dot` format -You can use the `format="dot"` option to output the return message in the DOT language, and then use Graphviz to generate a graph of the plan. +You can use the `format="dot"` option to output the return message in the `dot` language, and then use Graphviz to generate a graph of the plan. !!! note - Graphviz is open source graph visualization software. - -Graphviz provides an online tool for previewing DOT language files and exporting them to other formats such as SVG or JSON. For more information, see [Graphviz Online](https://dreampuf.github.io/GraphvizOnline/). + Graphviz is open source graph visualization software. Graphviz provides an online tool for previewing DOT language files and exporting them to other formats such as SVG or JSON. For more information, see [Graphviz Online](https://dreampuf.github.io/GraphvizOnline/). ```ngql nebula> EXPLAIN format="dot" SHOW TAGS; @@ -109,6 +111,6 @@ Execution Plan --------------------------------------------------------------------------------------------------------------------------------------------- ------------- ``` -Transformed into a Graphviz graph, it is as follows: +The Graphviz graph transformed from the above DOT statement is as follows. ![Graphviz graph of EXPLAIN SHOW TAGS](https://docs-cdn.nebula-graph.com.cn/docs-2.0/3.ngql-guide/16.query-tuning-statements/explain-show-tags.png)