Cabin and Secondary Indexes

A Cabin is a lookup structure over a column or an expression (DATE(ts)), and it holds only the values that queries have actually asked for. For each observed value it is complete (a superset that the reader filters). For all other values it pays no index-like write cost. If a set for one value is dropped, queries that ask for that value fall back to a tree search, and the results stay the same. KDBS describes a secondary index as "a Cabin that has observed every value".

Key Specifications

ItemSecondary index (CREATE INDEX)Cabin (CREATE CABIN ON)
Values heldAll rowsOnly values observed by single-value statements (col = v)
KeyUp to 4 columns + up to 8 COVERING columnsOne column, an immutable function (DATE(ts)), or an AND of comparisons (conditional Cabin)
Write costEvery write adds an entryOnly observed values
MaintenanceAppend-only. DELETE does not touch the indexIn memory. On restart the entries disappear and only the catalog row remains
Index-only readNone. COVERING only saves the table lookupNone
Target tableBTREE (the entry's value is the tuple key)All. Not allowed for tuple keys and NO CABIN columns
UniqueCREATE UNIQUE INDEXNone
Online creationCREATE INDEX outside a transaction builds without blocking writes
CleanupREINDEX INDEX (rebuild), PURGE INDEX (remove dead entries)DROP CABIN ON t(col)

How an Index Is Used

  • Equality: WHERE status = 'PAID' becomes IndexProbe. An IN list becomes a key set on one of the leading equality columns (key_set=n, once per value).
  • Range: BETWEEN or a comparison bounded on both sides becomes IndexRange.
  • Instead of sorting: If the index starts with the equality columns of the WHERE and the ORDER BY columns follow exactly (all ascending or all descending), the executor reads only the first N rows under LIMIT without sorting and stops (order=index_asc, order=index_desc). An index does not replace sorting for varchar and char columns. The index keeps only the prefix of the string as its key.
  • Order among equal values: Reading an index in ascending order returns equal values in ascending tuple-key order, and in descending order, in descending tuple-key order. For this reason KDBS rejects an index that ends with the tuple key (the tuple key already has an index - the clustered tree is it).
  • String keys: Sorted by the first 32 bytes and compared in full. If many values share the same first 32 bytes, every read costs an extra lookup.
  • The indexes = off setting stops reads from using indexes, but the compiled plan (IndexProbe) stays the same. There is deliberately no setting that turns off index maintenance. An index that is not maintained is not slow, it is wrong.

Cabin Controller

If a column is declared CABIN AUTO or nothing is specified (the default is AUTO), the experimental Cabin controller (cabin_optimizer, default off) can create and drop Cabins based on execution statistics. A Cabin created by the controller is used only when an administrator plan names it with ACCESS t CABIN (col). NO CABIN never creates a Cabin by any path.

Inspection

SHOW INDEXES;   -- sys.indexes: unique, probes, ranges, entries_scanned, last_used
SHOW CABINS;    -- sys.cabins: shape(column, expression, predicate), key
ANALYZE SELECT * FROM orders WHERE cust_id = 101 ORDER BY ord_dt DESC LIMIT 5;
-- step 0 IndexProbe orders order=index_desc

An index whose probes and ranges in sys.indexes stay at 0 is an index that no SELECT has read (unique checks and write maintenance are not counted).

Comparison with Other DBMSs

KDBSOraclePostgreSQL
Value of an index entryTuple keyROWIDctid
Index-only readNoneINDEX FAST FULL SCAN, etc.Index Only Scan (needs VM)
CoveringCOVERING (…) (only skips the lookup)Add columns to the indexINCLUDE (…)
Partial indexConditional CabinImitated with a function-based indexWHERE partial index
Cleanup of deleted entriesPURGE INDEXReuseVACUUM

Related pages