ANALYZE

v3.2.0

Run a SELECT and report how it actually executed: steps, access methods, rows examined and pages read.

In this article

Runs a SELECT with statistics collection turned on and reports what happened: each step’s access method, the rows examined, and the pages read. It reports the run that actually took place, not an estimate.

Syntax

ANALYZE <select statement>

Example

ANALYZE SELECT * FROM passengers WHERE id = 1;
analyze rows=1 class=PointSelect steps=1 examined=1 pages=1 opens=1 pattern_id=0x40a5b5e4e01959eb fetch_id=0x9b8e7707127bd8d4
class=PointSelect steps=1 hoisted=0
step 0 Lookup passengers key=1
  filter 0:0.0 = 1
project * (4 column(s) of step 0)
step 0 Lookup passengers opens=1 examined=1 matched=1 sel=100% pages=1

Output

FieldMeaning
rowsRows returned.
classThe statement’s execution class, decided when it was parsed, such as PointSelect.
stepsNumber of steps in the plan. One step per table access.
examinedRows the engine looked at. For a sorted LIMIT, this is every matching row.
pagesPages read.
pattern_idIdentifies the statement’s shape. Statements that differ only in literal values share it, and its plan never changes.
fetch_idThe shape without the select list; the identifier listed by SHOW PATTERNS.

Further lines describe each step: its access method (key lookup, range, index, Cabin, scan), whether a sort ran, and whether a join built an in-memory lookup table for its inner side (build, inner_built).

Remarks

  • ANALYZE uses the same parse, plan and fingerprint as the plain statement.

  • An ORDER BY on the primary key ascending shows no sort step, because none is needed.

  • A condition with OR, NOT, an IN list or LIKE shows as one filter bool (...) line. It filters the rows its step reads and is never used as a key:

    kdbs> ANALYZE SELECT * FROM flights WHERE id = 1 OR id = 3
    analyze rows=2 class=JoinSelect steps=1 examined=4 pages=1 opens=1 pattern_id=0x3f1b0bf6a55fcdac fetch_id=0x292001fdeb6436ad
    class=JoinSelect steps=1 hoisted=0
    step 0 Scan flights
      filter bool (0:0.0 = 1 OR 0:0.0 = 3)
    project * (8 column(s) of step 0)
    step 0 Scan flights opens=1 examined=4 matched=2 sel=50% pages=1
    

Limitations

  • SELECT only. A write statement cannot be analyzed.

  • Only a statement that runs as a step chain. A SELECT that only the query layer answers (an outer join, SELECT * across a join, DISTINCT, HAVING, a set operation, a derived table, an expression in the select list; see SELECT) is refused with the step-chain path’s own refusal:

    kdbs> ANALYZE SELECT flight_id, COUNT(*) FROM tickets GROUP BY flight_id HAVING COUNT(*) > 1
    ERR NOT_IMPLEMENTED retryable=0 HAVING is not supported yet (byte 66); filter before the fold with WHERE, or filter the result client-side
    

See also