8.18. EXPLAIN

Synopsis

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

Description

Show the logical or distributed execution plan of a statement, or validate the statement.Use TYPE DISTRIBUTED option to display fragmented plan. Each plan fragment is executed bya single or multiple Presto nodes. Fragments separation represent the data exchange between Presto nodes.Fragment type specifies how the fragment is executed by Presto nodes and how the data isdistributed between fragments:

SINGLE
Fragment is executed on a single node.
HASH
Fragment is executed on a fixed number of nodes with the input datadistributed using a hash function.
ROUND_ROBIN
Fragment is executed on a fixed number of nodes with the input datadistributed in a round-robin fashion.
BROADCAST
Fragment is executed on a fixed number of nodes with the input databroadcasted to all nodes.
SOURCE
Fragment is executed on nodes where input splits are accessed.

Examples

Logical plan:

  1. presto: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

Distributed plan:

  1. presto: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.  
  11. Fragment 1 [HASH]
  12. Output layout: [regionkey, count]
  13. Output partitioning: SINGLE []
  14. - Aggregate(FINAL)[regionkey] => [regionkey:bigint, count:bigint]
  15. count := "count"("count_8")
  16. - LocalExchange[HASH][$hashvalue] ("regionkey") => regionkey:bigint, count_8:bigint, $hashvalue:bigint
  17. - RemoteSource[2] => [regionkey:bigint, count_8:bigint, $hashvalue_9:bigint]
  18.  
  19. Fragment 2 [SOURCE]
  20. Output layout: [regionkey, count_8, $hashvalue_10]
  21. Output partitioning: HASH [regionkey][$hashvalue_10]
  22. - Project[] => [regionkey:bigint, count_8:bigint, $hashvalue_10:bigint]
  23. $hashvalue_10 := "combine_hash"(BIGINT '0', COALESCE("$operator$hash_code"("regionkey"), 0))
  24. - Aggregate(PARTIAL)[regionkey] => [regionkey:bigint, count_8:bigint]
  25. count_8 := "count"(*)
  26. - TableScan[tpch:tpch:nation:sf0.1, originalConstraint = true] => [regionkey:bigint]
  27. regionkey := tpch:regionkey

Validate:

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

See Also

EXPLAIN ANALYZE

原文: https://prestodb.io/docs/current/sql/explain.html