Skip to main content

EXPLAIN

EXPLAIN

  • Shows how a query will be executed, including logical and distributed execution plans.
  • The query is not actually run, so no data is scanned.

Overview

EXPLAIN [ ( option [, ...] ) ] statement

-- Options:
FORMAT { TEXT | GRAPHVIZ | JSON }
TYPE { LOGICAL | DISTRIBUTED | VALIDATE | IO }

Parameters

FORMAT { TEXT | GRAPHVIZ | JSON }
  • Specifies output format as TEXT, GRAPHVIZ, or JSON.
    Default is TEXT.
TYPE { LOGICAL | DISTRIBUTED | VALIDATE | IO }
  • LOGICAL: Provides a logical execution plan.
  • DISTRIBUTED: Provides a distributed execution plan.
  • IO: Adds info on tables and schemas read by the query (output is JSON only).
Examples
EXPLAIN Example
EXPLAIN (TYPE LOGICAL, FORMAT JSON)
SELECT regionkey, count(*) FROM nation GROUP BY 1;

EXPLAIN ANALYZE

  • Executes the query and shows the distributed execution plan along with task cost.
  • The query is actually run, so data is scanned. Execution time may vary based on the query.

Overview

EXPLAIN ANALYZE [VERBOSE] statement

Parameters

VERBOSE
  • Provides more details and low-level stats (stats may not be accurate).
Examples
EXPLAIN ANALYZE Example
EXPLAIN ANALYZE VERBOSE
SELECT count(clerk) OVER()
FROM orders
WHERE orderdate > date '1995-01-01';