8.22. EXPLAIN ANALYZE

Synopsis

  1. EXPLAIN ANALYZE [VERBOSE] statement

Description

Execute the statement and show the distributed execution plan of the statementalong with the cost of each operation.

The VERBOSE option will give more detailed information and low-level statistics;understanding these may require knowledge of Presto internals and implementation details.

Note

The stats may not be entirely accurate, especially for queries that complete quickly.

Examples

In the example below, you can see the CPU time spent in each stage, as well as the relativecost of each plan node in the stage. Note that the relative cost of the plan nodes is based onwall time, which may or may not be correlated to CPU time. For each plan node you can seesome additional statistics (e.g: average input per node instance, average number of hash collisions forrelevant plan nodes). Such statistics are useful when one wants to detect data anomalies for a query(skewness, abnormal hash collisions).

  1. presto:sf1> EXPLAIN ANALYZE SELECT count(*), clerk FROM orders WHERE orderdate > date '1995-01-01' GROUP BY clerk;
  2.  
  3. Query Plan
  4. -----------------------------------------------------------------------------------------------
  5. Fragment 1 [HASH]
  6. Cost: CPU 88.57ms, Input: 4000 rows (148.44kB), Output: 1000 rows (28.32kB)
  7. Output layout: [count, clerk]
  8. Output partitioning: SINGLE []
  9. - Project[] => [count:bigint, clerk:varchar(15)]
  10. Cost: 26.24%, Input: 1000 rows (37.11kB), Output: 1000 rows (28.32kB), Filtered: 0.00%
  11. Input avg.: 62.50 lines, Input std.dev.: 14.77%
  12. - Aggregate(FINAL)[clerk][$hashvalue] => [clerk:varchar(15), $hashvalue:bigint, count:bigint]
  13. Cost: 16.83%, Output: 1000 rows (37.11kB)
  14. Input avg.: 250.00 lines, Input std.dev.: 14.77%
  15. count := "count"("count_8")
  16. - LocalExchange[HASH][$hashvalue] ("clerk") => clerk:varchar(15), count_8:bigint, $hashvalue:bigint
  17. Cost: 47.28%, Output: 4000 rows (148.44kB)
  18. Input avg.: 4000.00 lines, Input std.dev.: 0.00%
  19. - RemoteSource[2] => [clerk:varchar(15), count_8:bigint, $hashvalue_9:bigint]
  20. Cost: 9.65%, Output: 4000 rows (148.44kB)
  21. Input avg.: 4000.00 lines, Input std.dev.: 0.00%
  22.  
  23. Fragment 2 [tpch:orders:1500000]
  24. Cost: CPU 14.00s, Input: 818058 rows (22.62MB), Output: 4000 rows (148.44kB)
  25. Output layout: [clerk, count_8, $hashvalue_10]
  26. Output partitioning: HASH [clerk][$hashvalue_10]
  27. - Aggregate(PARTIAL)[clerk][$hashvalue_10] => [clerk:varchar(15), $hashvalue_10:bigint, count_8:bigint]
  28. Cost: 4.47%, Output: 4000 rows (148.44kB)
  29. Input avg.: 204514.50 lines, Input std.dev.: 0.05%
  30. Collisions avg.: 5701.28 (17569.93% est.), Collisions std.dev.: 1.12%
  31. count_8 := "count"(*)
  32. - ScanFilterProject[table = tpch:tpch:orders:sf1.0, originalConstraint = ("orderdate" > "$literal$date"(BIGINT '9131')), filterPredicate = ("orderdate" > "$literal$date"(BIGINT '9131'))] => [cler
  33. Cost: 95.53%, Input: 1500000 rows (0B), Output: 818058 rows (22.62MB), Filtered: 45.46%
  34. Input avg.: 375000.00 lines, Input std.dev.: 0.00%
  35. $hashvalue_10 := "combine_hash"(BIGINT '0', COALESCE("$operator$hash_code"("clerk"), 0))
  36. orderdate := tpch:orderdate
  37. clerk := tpch:clerk

When the VERBOSE option is used, some operators may report additional information.For example, the window function operator will output the following:

  1. EXPLAIN ANALYZE VERBOSE SELECT count(clerk) OVER() FROM orders WHERE orderdate > date '1995-01-01';
  2.  
  3. Query Plan
  4. -----------------------------------------------------------------------------------------------
  5. ...
  6. - Window[] => [clerk:varchar(15), count:bigint]
  7. Cost: {rows: ?, bytes: ?}
  8. CPU fraction: 75.93%, Output: 8130 rows (230.24kB)
  9. Input avg.: 8130.00 lines, Input std.dev.: 0.00%
  10. Active Drivers: [ 1 / 1 ]
  11. Index size: std.dev.: 0.00 bytes , 0.00 rows
  12. Index count per driver: std.dev.: 0.00
  13. Rows per driver: std.dev.: 0.00
  14. Size of partition: std.dev.: 0.00
  15. count := count("clerk")
  16. ...

See Also

EXPLAIN