CREATE CABIN, DROP CABIN

v3.2.0

Track the rows for the values queries actually ask for on a column, without the write cost of a full index.

In this article

A Cabin speeds up column = value lookups like an index does, but it covers only the values that queries have actually asked for. A write pays for a Cabin only when it touches one of those values, so a Cabin suits columns where a few values are looked up often.

For each value a Cabin has observed, it knows every matching row. For a value it has not observed, the lookup falls back to a scan. Dropping part or all of a Cabin can make queries slower, never wrong.

Syntax

CREATE CABIN ON <table> (<column> | <expression> | <predicate>)
DROP CABIN ON <table> (<column> | <expression> | <predicate>)

A Cabin has no name of its own; it is identified by its table and what it is on. It comes in three shapes:

ShapeWritten asServes
Columna non-key column, (name)name = 'v', and a join on that column
Expressionan immutable function of columns, (DATE(ts))DATE(ts) = '2026-10-16'; for DATE, also a range of ts bounded on both sides
Predicatean AND of comparisons of a column or a function call with a literal, (member = 1 AND joined_on > '2020-01-01')a query whose own conditions include every one of those comparisons, exactly as written

Examples

CREATE CABIN ON passengers(name);
CREATED CABIN on=passengers.name cabin_id=1 column=1 observed=0
WARN no recorded access has filtered 'passengers.name'; this cabin will stay empty until traffic probes that column by equality (SHOW ACCESS lists what has been recorded)
SELECT * FROM passengers WHERE name = 'Kim Minjun';   -- the first lookup observes 'Kim Minjun'
SHOW CABINS;
DROP CABIN ON passengers(name);

An expression Cabin

kdbs> CREATE TABLE trades (id int64, sym char(8), ts timestamp, qty int64)
CREATED oid=4047
kdbs> INSERT INTO trades VALUES ('KDBS', '2026-10-15 09:30:00', 10)
INSERTED oid=4047 id=1 page=157 slot=0
kdbs> INSERT INTO trades VALUES ('KDBS', '2026-10-16 10:00:00', 5)
INSERTED oid=4047 id=2 page=157 slot=1
kdbs> CREATE CABIN ON trades (DATE(ts))
CREATED CABIN on=trades (DATE(ts)) cabin_id=2 observed=0
kdbs> SELECT * FROM trades WHERE DATE(ts) = '2026-10-16'
id   sym                   ts  qty
--  ----  -------------------  ---
 2  KDBS  2026-10-16 10:00:00    5

A predicate Cabin

kdbs> CREATE CABIN ON passengers (member = 1 AND joined_on > '2020-01-01')
CREATED CABIN on=passengers (member = 1 AND joined_on > '2020-01-01') cabin_id=1 observed=0
kdbs> SELECT * FROM passengers WHERE member = 1 AND joined_on > '2020-01-01'
id         name  member   joined_on
--  -----------  ------  ----------
 2  Lee Seoyeon       1  2021-07-02
 5    Jung Hana       1  2020-11-30
kdbs> ANALYZE SELECT * FROM passengers WHERE member = 1 AND joined_on > '2020-01-01'
analyze rows=2 class=JoinSelect steps=1 examined=2 pages=4 opens=1 pattern_id=0x1825283dbeaab222 fetch_id=0x67069d2ab95d6949
class=JoinSelect steps=1 hoisted=0
step 0 CabinProbe passengers cabin=1 on=$2 = i1 AND $3 > i18262 value=1
  filter 0:0.2 = 1
  filter 0:0.3 > 18262
project * (4 column(s) of step 0)
step 0 CabinProbe passengers opens=1 examined=2 matched=2 sel=100% pages=4 cabin_hits=1 cabin_entries=2 hint_hits=2
kdbs> SHOW CABINS
cabin_id,rel_oid,rel_name,column,origin,status,observed,entries,hits,misses,shape,key
1,4025,passengers,NULL,user,active,1,2,1,1,predicate,member = 1 AND joined_on > '2020-01-01'

SHOW CABINS gives each Cabin’s shape (column, expression or predicate) and its key.

Column policy

CREATE TABLE can set, per column, who may create a Cabin on it:

PolicyMeaning
CABINCreate a Cabin now.
CABIN AUTOThe engine may decide later.
NO CABINNever, by any route.
(none)Treated as CABIN AUTO.

How it works

  • The first lookup of a value scans the table and records every matching row’s primary key. Later lookups of that value read only those rows.
  • Writes add entries for observed values; nothing is removed on the write path. Each read checks entries against the current row and its visibility, so extra entries cost a little time and never change a result.
  • The engine’s optimizer can create and drop column Cabins on CABIN AUTO columns by itself when the server setting cabin_optimizer is on. It is off by default. It never creates an expression or predicate Cabin.
  • A Cabin follows its columns by position, so RENAME COLUMN keeps it. A column a Cabin is on cannot be dropped.
  • An expression or predicate CREATE CABIN holds the table exclusively while it runs.

Limitations

  • A column Cabin is on one column. There are no multi-column keys.
  • A predicate cannot use OR, NOT, BETWEEN, a subquery or a comparison between two columns.
  • Not allowed on the primary key, or on an expression that reads only the primary key or no column, or on a NO CABIN column.
  • Cabin contents are kept in memory. After a restart only the declaration remains, and traffic fills the Cabin again.

See also