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
| Item | Secondary index (CREATE INDEX) | Cabin (CREATE CABIN ON) |
|---|---|---|
| Values held | All rows | Only values observed by single-value statements (col = v) |
| Key | Up to 4 columns + up to 8 COVERING columns | One column, an immutable function (DATE(ts)), or an AND of comparisons (conditional Cabin) |
| Write cost | Every write adds an entry | Only observed values |
| Maintenance | Append-only. DELETE does not touch the index | In memory. On restart the entries disappear and only the catalog row remains |
| Index-only read | None. COVERING only saves the table lookup | None |
| Target table | BTREE (the entry's value is the tuple key) | All. Not allowed for tuple keys and NO CABIN columns |
| Unique | CREATE UNIQUE INDEX | None |
| Online creation | CREATE INDEX outside a transaction builds without blocking writes | |
| Cleanup | REINDEX INDEX (rebuild), PURGE INDEX (remove dead entries) | DROP CABIN ON t(col) |
How an Index Is Used
- Equality:
WHERE status = 'PAID'becomesIndexProbe. An IN list becomes a key set on one of the leading equality columns (key_set=n, once per value). - Range:
BETWEENor a comparison bounded on both sides becomesIndexRange. - Instead of sorting: If the index starts with the equality columns of the
WHEREand theORDER BYcolumns follow exactly (all ascending or all descending), the executor reads only the first N rows underLIMITwithout sorting and stops (order=index_asc,order=index_desc). An index does not replace sorting forvarcharandcharcolumns. 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 = offsetting 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
| KDBS | Oracle | PostgreSQL | |
|---|---|---|---|
| Value of an index entry | Tuple key | ROWID | ctid |
| Index-only read | None | INDEX FAST FULL SCAN, etc. | Index Only Scan (needs VM) |
| Covering | COVERING (…) (only skips the lookup) | Add columns to the index | INCLUDE (…) |
| Partial index | Conditional Cabin | Imitated with a function-based index | WHERE partial index |
| Cleanup of deleted entries | PURGE INDEX | Reuse | VACUUM |