Step Chain and ANALYZE

KDBS has no stage where a cost-based optimizer searches plan candidates. A statement that reads as basic syntax is compiled directly into a step chain at parse time. A step is one of key lookup, probe, range, scan, or sub-chain, and for every row the previous step emits, the next step runs. The access method is decided only by the statement's shape and the catalog, without looking at data statistics. The only thing the engine picks using statistics is the order of an inner join (Join order and plan).

Key specs

ItemValue
Access method choiceTuple key → secondary index → Cabin → filter scan, in a fixed priority
JoinA chain of inner equi-joins. Probe if it is a tuple key, otherwise index, Cabin, or scan. No merge join
Hash buildIf the inner table has neither an index nor Cabin, builds an in-memory map once per statement (join_build_max_rows, default 65,536 rows)
SortIn memory only. Fails if it exceeds sort_max_rows (default 1,048,576)
SubqueryOnly in condition position (step chain). Up to depth 4. An uncorrelated EXISTS runs once first
Query layerOuter joins, UNION, INTERSECT, EXCEPT, derived tables, expressions and scalar subqueries in the select list, HAVING, sort by expression

Step types

These are the step names in ANALYZE output.

StepMeaningClosest in other DBMSs
LookupDescends the B+ tree once by tuple key equality. With key_set=n, once per value in the IN listINDEX UNIQUE SCAN + table access (clustered)
RangeTuple key range. Seeks to the low end and stops at the high endClustered index Range Scan
IndexProbe / IndexRangeGets the tuple key by secondary index equality / range and reads the rowINDEX RANGE SCAN + TABLE ACCESS BY ROWID
ScanWhole tableTABLE ACCESS FULL
FilterScanReads everything and filters by conditionFULL with a filter
ProbeFinds the inner side of a join by the previous step's value (tuple key, index)Inner side of an NL join

Reading ANALYZE

ANALYZE <SELECT> turns on statistics collection, actually runs the statement, and returns what it did instead of the rows. The first part is the compiled chain, and the second part is the execution result per step.

analyze rows=2 class=JoinSelect steps=2 examined=5 pages=3 opens=3 pattern_id=0x1236… fetch_id=0x4dd0…
class=JoinSelect steps=2 hoisted=0
planned order=written gen=0 switch=1 est=0:1000,1:1000 capture=deferred
step 0 FilterScan orders AS o
  filter 0:0.3 = 'DONE'
step 1 Probe customers AS c key=0:0.1
  filter 0:1.0 = 0:0.1
project o.ord_id=0:0.0, c.cust_nm=0:1.1
step 0 FilterScan orders AS o opens=1 examined=3 matched=2 sel=66% pages=1
step 1 Probe customers AS c opens=2 examined=2 matched=2 sel=100% pages=2 memo_hits=1
DB time 0.24 ms = CPU 0.24
ValueMeaningSandbox execution plan table
opensNumber of times the step was opened (once per row of the previous step)Starts
examinedNumber of rows the step filtered. Includes rows rejected early by the stored bytesTrace tab
matchedNumber of rows that passed the condition and were passed onA-Rows
selmatched / examined
pagesNumber of pages the step readBuffers
0:1.2Column 2 of the row emitted by step 1 of block 0access/filter condition
planned …How the join order was decided (Join order). est= is the expected row count per stepE-Rows
order=index_desc, order=tuple_key_descThe sort is replaced by index or tuple key order (no sort line)
memo_hits, inner_built, build_rowsSkipping a repeated lookup of the same key, hash build
DB timeSum of CPU and time per wait eventA-Time, Trace tab

If examined is much larger than matched, many rows were read and discarded. It is the same place where other DBMSs look at "was it filtered by the index or by the table".

Query layer

A statement the step chain cannot carry (outer joins, set operations, SELECT amount * 2, HAVING …) is answered by the query layer. For each table, it receives rows through a single-table lookup that carries the top-level WHERE conditions pointing only at that table, and computes the joins, remaining conditions, select list, and sort over the received rows. The layer's joins hash on the ON equality, and the order is the order written.

  • A statement that basic syntax answered is answered exactly as before. The layer takes only statements that basic syntax rejected.
  • Every row set the layer holds is bounded by sort_max_rows. Exceeding it yields RESOURCE_EXHAUSTED, not a partial result.
  • ANALYZE does not explain a layer statement and returns the rejection message of basic syntax. The sandbox shows only the rows in this case and leaves that message in the Raw tab.
-- The layer answers: a result is returned, but ANALYZE says 'outer joins are not supported'
SELECT c.cust_id, o.ord_id FROM customers AS c LEFT JOIN orders AS o ON o.cust_id = c.cust_id WHERE c.cust_id = 1;

Comparison with other DBMSs

KDBSOraclePostgreSQL
PlanningStep chain at compile time, statistics only for join orderCost-based, query transformationCost-based
Actual statisticsANALYZE <select>GATHER_PLAN_STATISTICS, DISPLAY_CURSOREXPLAIN (ANALYZE, BUFFERS)
Amount readpages per stepBuffersshared hit + read
Query transformationProhibited (no decorrelation rewrite)Subquery unnesting, etc.Pull-up, etc.

Related pages