Documentation / Guide
Issue boardGitLab source
Guide Developer guide

Storage backend

The storage side turns typed row and search operations into bounded memory access and page reads/writes. This is the main work area for the storage/search owner.

Memory and disk

flowchart TB
    EX[Executor requests a row or range] --> TYPE{Operation}
    TYPE -->|row operations| REC[Record store and row codec]
    TYPE -->|key lookup| IDX[B+ tree index manager]
    IDX --> RID[Candidate RIDs: page and slot]
    RID --> REC
    REC --> BP[Buffer pool: fixed frame budget]
    IDX --> BP
    BP --> HIT{Page cached?}
    HIT -->|yes| PIN[Pin page and return RAII guard]
    HIT -->|no| VICTIM[Choose an unpinned victim]
    VICTIM --> DIRTY{Victim dirty?}
    DIRTY -->|yes| WRITE[Write old page first]
    DIRTY -->|no| READ[Read requested page]
    WRITE --> READ
    READ --> PIN
    READ --> FILE[(Page files on disk)]
    WRITE --> FILE
    PIN --> RELEASE[Guard releases pin; writes mark dirty]

A page is a fixed-size chunk of a file. A buffer frame holds one page in memory. Pinning means a caller is still using that page, so the cache cannot reuse its memory. A dirty page has changes that need writing to disk.

Proposed durable layout

data/
  catalog.meta
  databases/<database-id>/
    catalog.meta
    tables/<table-id>.rows
    indexes/<index-id>.btree

This layout is a team proposal. Store numeric IDs in paths and keep names in metadata. Use versioned headers, explicit byte encoding and validated lengths. An 8 KiB page and a slotted record layout are practical starting points; review them before freezing the file format. Do not dump compiler-dependent C++ structs directly to disk.

A stable RID consists of page_id and slot_id. A row is decoded into owned values before a page guard is released. Strings growing during UPDATE must not silently invalidate index RIDs; choose a slot/overflow strategy or a bounded schema-sized representation and document it.

How the B+ tree helps

flowchart TB
    ROOT[Internal root: separator 30] -->|keys below 30| L1[Leaf: 10 RID-A, 20 RID-B]
    ROOT -->|keys 30 and above| L2[Leaf: 30 RID-C, 40 RID-D]
    L1 -->|next leaf for ranges| L2
    L1 --> R1[(Record pages)]
    L2 --> R1

Internal nodes guide a search; leaves store keys paired with record IDs. Linked leaves support range scans. A B+ tree has many children per internal page, keeping its height small and reducing disk reads. Duplicates in an ordinary index are legal, so identify an entry with both key and RID.

An index on (a,b) uses lexicographic order. It can narrow a search on a or on both a and b; a predicate on b alone generally needs another access path. Keep residual predicates in the executor so an index choice never changes query results.

Keeping rows and indexes consistent

sequenceDiagram
    participant EX as Write executor
    participant CM as Constraint manager
    participant WM as Write coordinator
    participant RS as Record store
    participant IX as All affected indexes
    EX->>CM: Validate candidate row and references
    CM-->>EX: Accept or typed rejection
    EX->>WM: Apply validated mutation
    WM->>RS: Reserve/change row
    WM->>IX: Erase old / insert new key-RID entries
    WM->>WM: Finish or undo partial in-process change
    WM-->>EX: Affected rows or I/O failure

This is an in-process consistency contract, not a claim of full transaction recovery. Normal exit and EOF flush dirty pages and metadata. The course requires persistence across orderly restarts and does not require crash consistency.

Optimize after the boundaries work

First make page reads, row scans, tree comparisons and mutations correct. Then measure equality/range lookup, selective joins and streaming import on the provided data. Count page reads as well as time; include cache state and identical-result checks. Avoid loading a full table or Cartesian product into memory.

The course environment targets approximately 3600 seconds, 256 MiB virtual memory, 10 GB disk and one CPU. A proposed 48–64 MiB page cache leaves room for code, parser, rows and results, but the whole process must be measured. See official runtime limits.

DBS 005 · Specification v1 · Team review required for proposed interfaces.
Engine behavior is planned; implementation progress lives in GitLab.