Skip to main content

Module cell

Module cell 

Source
Expand description

Cell format: one row per cell, hand-rolled length-prefixed encoding.

A cell represents a single row in a table, identified by its ROWID. The layout is deliberately SQLite-adjacent but not bit-compatible:

┌──────────────────────────────────────────────────────────────────┐
│ cell_length    varint      total bytes *after* this field,       │
│                            including the kind tag below          │
│ kind_tag       u8          0x01 = local cell (this module)       │
│                            0x02 = overflow pointer (see          │
│                            `OverflowRef` in `overflow.rs`)       │
│ rowid          zigzag varint                                     │
│ col_count      varint      number of declared columns            │
│ null_bitmap    ⌈col_count/8⌉ bytes                               │
│                 bit 0 of byte 0 = column 0, little-endian order  │
│ value_blocks   one block per non-NULL column, in column order    │
└──────────────────────────────────────────────────────────────────┘

A value block is a one-byte tag followed by type-specific bytes:

  0x00 Integer    i64 zigzag-varint
  0x01 Real       f64 little-endian, 8 bytes
  0x02 Text       varint length, UTF-8 bytes
  0x03 Bool       u8 (0 or 1)

Design notes:

  • The null bitmap is duplicated information (the stream of value blocks could also carry a “Null” tag), but it’s faster to skip over absent columns when projecting, and more compact when many columns are null.
  • Integer values are stored as i64 on disk even though the in-memory Row::Integer storage today uses i32. Widening is lossless and makes the format stable against a future storage widening.
  • Real values are f64 fixed-width rather than an encoded variant — the value is already floating-point, so entropy-based compression wouldn’t help much, and fixed-width keeps decoding simple.
  • cell_length does not include its own bytes. This lets a reader skip a cell without decoding it: advance by (cell_length varint) bytes + cell_length value.

Modules§

tag
Value type tag stored in each non-NULL value block.

Structs§

Cell
A decoded cell: one row’s worth of values plus its rowid.

Constants§

KIND_INDEX
KIND_INTERIOR
KIND_LOCAL
Cell kind tags — first byte of every cell’s body after the length prefix. Readers dispatch on this to produce one of:
KIND_OVERFLOW