EXPLAIN

摘要

  1. EXPLAIN [ ( option [, ...] ) ] statement
  2. where option can be one of:
  3. FORMAT { TEXT | GRAPHVIZ | JSON }
  4. TYPE { LOGICAL | DISTRIBUTED | VALIDATE | IO }

说明

显示语句的逻辑或分布式执行计划,或者对语句进行验证。使用 TYPE DISTRIBUTED 选项可以显示分片计划。每个计划片段由单个或多个 openLooKeng 节点执行。片段之间的间隔表示 openLooKeng 节点之间的数据交换。片段类型指定 openLooKeng 节点如何执行片段以及数据如何在片段之间分布:

SINGLE

片段在单个节点上执行。

HASH

片段在固定数量的节点上执行,输入数据通过哈希函数进行分布。

ROUND_ROBIN

片段在固定数量的节点上执行,输入数据以轮循方式进行分布。

BROADCAST

片段在固定数量的节点上执行,输入数据广播到所有节点。

SOURCE

片段在访问输入分段的节点上执行。

示例

逻辑计划:

  1. lk:tiny> EXPLAIN SELECT regionkey, count(*) FROM nation GROUP BY 1;
  2. Query Plan
  3. ----------------------------------------------------------------------------------------------------------
  4. - Output[regionkey, _col1] => [regionkey:bigint, count:bigint]
  5. _col1 := count
  6. - RemoteExchange[GATHER] => regionkey:bigint, count:bigint
  7. - Aggregate(FINAL)[regionkey] => [regionkey:bigint, count:bigint]
  8. count := "count"("count_8")
  9. - LocalExchange[HASH][$hashvalue] ("regionkey") => regionkey:bigint, count_8:bigint, $hashvalue:bigint
  10. - RemoteExchange[REPARTITION][$hashvalue_9] => regionkey:bigint, count_8:bigint, $hashvalue_9:bigint
  11. - Project[] => [regionkey:bigint, count_8:bigint, $hashvalue_10:bigint]
  12. $hashvalue_10 := "combine_hash"(BIGINT '0', COALESCE("$operator$hash_code"("regionkey"), 0))
  13. - Aggregate(PARTIAL)[regionkey] => [regionkey:bigint, count_8:bigint]
  14. count_8 := "count"(*)
  15. - TableScan[tpch:tpch:nation:sf0.1, originalConstraint = true] => [regionkey:bigint]
  16. regionkey := tpch:regionkey

分布式计划:

  1. lk:tiny> EXPLAIN (TYPE DISTRIBUTED) SELECT regionkey, count(*) FROM nation GROUP BY 1;
  2. Query Plan
  3. ----------------------------------------------------------------------------------------------
  4. Fragment 0 [SINGLE]
  5. Output layout: [regionkey, count]
  6. Output partitioning: SINGLE []
  7. - Output[regionkey, _col1] => [regionkey:bigint, count:bigint]
  8. _col1 := count
  9. - RemoteSource[1] => [regionkey:bigint, count:bigint]
  10. Fragment 1 [HASH]
  11. Output layout: [regionkey, count]
  12. Output partitioning: SINGLE []
  13. - Aggregate(FINAL)[regionkey] => [regionkey:bigint, count:bigint]
  14. count := "count"("count_8")
  15. - LocalExchange[HASH][$hashvalue] ("regionkey") => regionkey:bigint, count_8:bigint, $hashvalue:bigint
  16. - RemoteSource[2] => [regionkey:bigint, count_8:bigint, $hashvalue_9:bigint]
  17. Fragment 2 [SOURCE]
  18. Output layout: [regionkey, count_8, $hashvalue_10]
  19. Output partitioning: HASH [regionkey][$hashvalue_10]
  20. - Project[] => [regionkey:bigint, count_8:bigint, $hashvalue_10:bigint]
  21. $hashvalue_10 := "combine_hash"(BIGINT '0', COALESCE("$operator$hash_code"("regionkey"), 0))
  22. - Aggregate(PARTIAL)[regionkey] => [regionkey:bigint, count_8:bigint]
  23. count_8 := "count"(*)
  24. - TableScan[tpch:tpch:nation:sf0.1, originalConstraint = true] => [regionkey:bigint]
  25. regionkey := tpch:regionkey

验证:

  1. lk:tiny> EXPLAIN (TYPE VALIDATE) SELECT regionkey, count(*) FROM nation GROUP BY 1;
  2. Valid
  3. -------
  4. true

IO:

  1. lk:hive> EXPLAIN (TYPE IO, FORMAT JSON) INSERT INTO test_nation SELECT * FROM nation WHERE regionkey = 2;
  2. Query Plan
  3. -----------------------------------
  4. {
  5. "inputTableColumnInfos" : [ {
  6. "table" : {
  7. "catalog" : "hive",
  8. "schemaTable" : {
  9. "schema" : "tpch",
  10. "table" : "nation"
  11. }
  12. },
  13. "columns" : [ {
  14. "columnName" : "regionkey",
  15. "type" : "bigint",
  16. "domain" : {
  17. "nullsAllowed" : false,
  18. "ranges" : [ {
  19. "low" : {
  20. "value" : "2",
  21. "bound" : "EXACTLY"
  22. },
  23. "high" : {
  24. "value" : "2",
  25. "bound" : "EXACTLY"
  26. }
  27. } ]
  28. }
  29. } ]
  30. } ],
  31. "outputTable" : {
  32. "catalog" : "hive",
  33. "schemaTable" : {
  34. "schema" : "tpch",
  35. "table" : "test_nation"
  36. }
  37. }
  38. }

另请参见

EXPLAIN ANALYZE