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
| Item | Value |
|---|---|
| Access method choice | Tuple key → secondary index → Cabin → filter scan, in a fixed priority |
| Join | A chain of inner equi-joins. Probe if it is a tuple key, otherwise index, Cabin, or scan. No merge join |
| Hash build | If 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) |
| Sort | In memory only. Fails if it exceeds sort_max_rows (default 1,048,576) |
| Subquery | Only in condition position (step chain). Up to depth 4. An uncorrelated EXISTS runs once first |
| Query layer | Outer 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.
| Step | Meaning | Closest in other DBMSs |
|---|---|---|
Lookup | Descends the B+ tree once by tuple key equality. With key_set=n, once per value in the IN list | INDEX UNIQUE SCAN + table access (clustered) |
Range | Tuple key range. Seeks to the low end and stops at the high end | Clustered index Range Scan |
IndexProbe / IndexRange | Gets the tuple key by secondary index equality / range and reads the row | INDEX RANGE SCAN + TABLE ACCESS BY ROWID |
Scan | Whole table | TABLE ACCESS FULL |
FilterScan | Reads everything and filters by condition | FULL with a filter |
Probe | Finds 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
| Value | Meaning | Sandbox execution plan table |
|---|---|---|
opens | Number of times the step was opened (once per row of the previous step) | Starts |
examined | Number of rows the step filtered. Includes rows rejected early by the stored bytes | Trace tab |
matched | Number of rows that passed the condition and were passed on | A-Rows |
sel | matched / examined | |
pages | Number of pages the step read | Buffers |
0:1.2 | Column 2 of the row emitted by step 1 of block 0 | access/filter condition |
planned … | How the join order was decided (Join order). est= is the expected row count per step | E-Rows |
order=index_desc, order=tuple_key_desc | The sort is replaced by index or tuple key order (no sort line) | |
memo_hits, inner_built, build_rows | Skipping a repeated lookup of the same key, hash build | |
DB time | Sum of CPU and time per wait event | A-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 yieldsRESOURCE_EXHAUSTED, not a partial result. ANALYZEdoes 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
| KDBS | Oracle | PostgreSQL | |
|---|---|---|---|
| Planning | Step chain at compile time, statistics only for join order | Cost-based, query transformation | Cost-based |
| Actual statistics | ANALYZE <select> | GATHER_PLAN_STATISTICS, DISPLAY_CURSOR | EXPLAIN (ANALYZE, BUFFERS) |
| Amount read | pages per step | Buffers | shared hit + read |
| Query transformation | Prohibited (no decorrelation rewrite) | Subquery unnesting, etc. | Pull-up, etc. |