跳转至

EXPLAIN 和 PROFILE

EXPLAIN语句输出 nGQL 语句的执行计划,但不会执行 nGQL 语句。

PROFILE语句执行 nGQL 语句,然后输出执行计划和执行概要。用户可以根据执行计划和执行概要优化查询性能。

执行计划

执行计划由 NebulaGraph 查询引擎中的执行计划器决定。

执行计划器将解析后的 nGQL 语句处理为actionaction是最小的执行单元。典型的action包括获取指定点的所有邻居、获取边的属性、根据条件过滤点或边等。每个action都被分配给一个operator

例如SHOW TAGS语句分为两个actionoperatorStartShowTags。更复杂的GO语句可能会被处理成 10 个以上的action

语法

  • EXPLAIN
    EXPLAIN [format= {"row" | "dot" | "tck"}] <your_nGQL_statement>;
    
  • PROFILE
    PROFILE [format= {"row" | "dot" | "tck"}] <your_nGQL_statement>;
    

输出格式

EXPLAINPROFILE语句的输出有三种格式:row(默认)、dottck。用户可以使用format选项修改输出格式。

row格式

row格式将返回信息输出到一个表格中。

  • EXPLAIN
    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
    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"}]    |
    -----+----------+--------------+----------------------------------------------------+----------------------------------------------------------------------
    
参数 说明
id operator的 ID。
name operator的名称。
dependencies 当前operator所依赖的operator的 ID。
profiling data 执行概要文件内容。 ver表示operator的版本;rows表示operator输出结果的行数;execTime表示执行action的时间;totalTime表示执行action的时间、系统调度时间、排队时间的总和。
operator info operator的详细信息。

dot格式

dot格式将返回 DOT 语言的信息,然后用户可以使用 Graphviz 生成计划图。

Note

Graphviz 是一款开源可视化图工具,可以绘制 DOT 语言脚本描述的图。Graphviz 提供一个在线工具,可以预览 DOT 语言文件,并将它们导出为 SVG 或 JSON 等其他格式。详情请参见 Graphviz Online

nebula> EXPLAIN format="dot" SHOW TAGS;
Execution succeeded (time spent 161/665 us)
Execution Plan
---------------------------------------------------------------------------------------------------------------------------------------------  -------------
  plan
---------------------------------------------------------------------------------------------------------------------------------------------  -------------
  digraph exec_plan {
      rankdir=LR;
      "ShowTags_0"[label="ShowTags_0|outputVar: \[\{\"colNames\":\[\],\"name\":\"__ShowTags_0\",\"type\":\"DATASET\"\}\]\l|inputVar:\l",   shape=Mrecord];
      "Start_2"->"ShowTags_0";
      "Start_2"[label="Start_2|outputVar: \[\{\"colNames\":\[\],\"name\":\"__Start_2\",\"type\":\"DATASET\"\}\]\l|inputVar: \l",   shape=Mrecord];
  }
---------------------------------------------------------------------------------------------------------------------------------------------  -------------

将上述示例的 DOT 语言转换为 Graphviz 图,如下所示。

Graphviz graph of EXPLAIN SHOW TAGS

tck格式

tck格式类似于表格,但是没有边框和行之间的间的分割线。用户可以将结果用在单元测试的测试用例中。 关于tck格式的测试用例,参见 TCK case

  • EXPLAIN
    nebula> EXPLAIN format="tck" FETCH PROP ON player "player_1","player_2","player_3" YIELD properties(vertex).name as name, properties(vertex).age as age;
    Execution succeeded (time spent 261µs/613.718µs)
    
    Execution Plan (optimize time 28 us)
    
    
    | id | name        | dependencies | profiling data | operator info |
    |  2 | Project     | 1            |                |               |
    |  1 | GetVertices | 0            |                |               |
    |  0 | Start       |              |                |               |
    
    
    Wed, 22 Mar 2023 23:15:52 CST
    
  • PROFILE
    nebula> PROFILE format="tck" FETCH PROP ON player "player_1","player_2","player_3" YIELD properties(vertex).name as name, properties(vertex).age as age;
    
    | name         | age |
    | "Piter Park" | 24  |
    | "aaa"        | 24  |
    | "ccc"        | 24  |
    
    Got 3 rows (time spent 1.474ms/2.19677ms)
    
    Execution Plan (optimize time 41 us)
    
    
    | id | name        | dependencies | profiling data                                                                                                      | operator info |
    |  2 | Project     | 1            | {"rows":3,"version":0}                                                                                              |               |
    |  1 | GetVertices | 0            | {"resp[0]":{"exec":"232(us)","host":"127.0.0.1:9779","total":"758(us)"},"rows":3,"total_rpc":"875(us)","version":0} |               |
    |  0 | Start       |              | {"rows":0,"version":0}                                                                                              |               |
    
    
    Wed, 22 Mar 2023 23:16:13 CST
    

最后更新: 2024年12月19日