Skip to main content

Module secondary_index

Module secondary_index 

Source
Expand description

Secondary indexes — a separate lookup structure per indexed column.

Every UNIQUE (or PRIMARY KEY) column gets one automatically at CREATE TABLE time. Explicit CREATE INDEX statements (Phase 3e.2) add more. On INSERT / UPDATE / DELETE the owning Table keeps its indexes in lockstep with its row storage.

Key shape. A B-Tree keyed by (value, rowid) would let us support duplicate values naturally. For simplicity the in-memory representation is BTreeMap<value, Vec<rowid>> — functionally equivalent, cheaper to iterate for a given value, a little heavier on the allocator for wide-dup columns. The on-disk representation in Phase 3e.4 will flatten to (value, rowid) keys one row per entry.

Types. Only Integer and Text columns are currently indexed. Real has floating-point equality hazards; Bool has so few distinct values an index isn’t worth it.

Structs§

SecondaryIndex
One secondary index on a single column. Multi-column composite indexes are on the longer-term list; the column_name field stays singular for now.

Enums§

IndexEntries
Typed map from value → list of rowids carrying that value. The rowid list is always non-empty; empty lists are pruned on remove.
IndexOrigin
Declares who created the index. Persisted into sqlrite_master.sql so the text round-trips; auto-created indexes get a synthesized SQL form so the catalog stays uniform.