ClickHouse/docs/en/sql-reference/statements/explain.md
Anna ac0ebd515e
DOCSUP-4193: Document the EXPLAIN statement (#17734)
* Add EXPLAIN query description

* Check examples

* update

* Update docs/en/sql-reference/statements/explain.md

Co-authored-by: BayoNet <da-daos@yandex.ru>

* Update docs/en/sql-reference/statements/explain.md

Co-authored-by: Nikolai Kochetov <KochetovNicolai@users.noreply.github.com>

Co-authored-by: BayoNet <da-daos@yandex.ru>
Co-authored-by: Nikolai Kochetov <KochetovNicolai@users.noreply.github.com>
2020-12-04 21:24:05 +03:00

3.4 KiB
Raw Blame History

toc_priority toc_title
39 EXPLAIN

EXPLAIN Statement

Show the execution plan of a statement.

Syntax:

EXPLAIN [AST | SYNTAX | PLAN | PIPELINE] [setting = value, ...] SELECT ... [FORMAT ...]

Example:

EXPLAIN SELECT sum(number) FROM numbers(10) UNION ALL SELECT sum(number) FROM numbers(10) ORDER BY sum(number) ASC FORMAT TSV;
Union
  Expression (Projection)
    Expression (Before ORDER BY and SELECT)
      Aggregating
        Expression (Before GROUP BY)
          SettingQuotaAndLimits (Set limits and quota after reading from storage)
            ReadFromStorage (SystemNumbers)
  Expression (Projection)
    MergingSorted (Merge sorted streams for ORDER BY)
      MergeSorting (Merge sorted blocks for ORDER BY)
        PartialSorting (Sort each block for ORDER BY)
          Expression (Before ORDER BY and SELECT)
            Aggregating
              Expression (Before GROUP BY)
                SettingQuotaAndLimits (Set limits and quota after reading from storage)
                  ReadFromStorage (SystemNumbers)

EXPLAIN Types

  • AST — Abstract syntax tree.
  • SYNTAX — Query text after AST-level optimizations.
  • PLAN — Query execution plan.
  • PIPELINE — Query execution pipeline.

EXPLAIN AST

Dump query AST.

Example:

EXPLAIN AST SELECT 1;
SelectWithUnionQuery (children 1)
 ExpressionList (children 1)
  SelectQuery (children 1)
   ExpressionList (children 1)
    Literal UInt64_1

EXPLAIN SYNTAX

Return query after syntax optimizations.

Example:

EXPLAIN SYNTAX SELECT * FROM system.numbers AS a, system.numbers AS b, system.numbers AS c;
SELECT
    `--a.number` AS `a.number`,
    `--b.number` AS `b.number`,
    number AS `c.number`
FROM
(
    SELECT
        number AS `--a.number`,
        b.number AS `--b.number`
    FROM system.numbers AS a
    CROSS JOIN system.numbers AS b
) AS `--.s`
CROSS JOIN system.numbers AS c

EXPLAIN PLAN

Dump query plan steps.

Settings:

  • header — Print output header for step. Default: 0.
  • description — Print step description. Default: 1.
  • actions — Print detailed information about step actions. Default: 0.

Example:

EXPLAIN SELECT sum(number) FROM numbers(10) GROUP BY number % 4;
Union
  Expression (Projection)
  Expression (Before ORDER BY and SELECT)
    Aggregating
      Expression (Before GROUP BY)
        SettingQuotaAndLimits (Set limits and quota after reading from storage)
          ReadFromStorage (SystemNumbers)

!!! note "Note" Step and query cost estimation is not supported.

EXPLAIN PIPELINE

Settings:

  • header — Print header for each output port. Default: 0.
  • graph — Use DOT graph description language. Default: 0.
  • compact — Print graph in compact mode if graph is enabled. Default: 1.

Example:

EXPLAIN PIPELINE SELECT sum(number) FROM numbers_mt(100000) GROUP BY number % 4;
(Union)
(Expression)
ExpressionTransform
  (Expression)
  ExpressionTransform
    (Aggregating)
    Resize 2  1
      AggregatingTransform × 2
        (Expression)
        ExpressionTransform × 2
          (SettingQuotaAndLimits)
            (ReadFromStorage)
            NumbersMt × 2 0  1

Оriginal article