Documentation / Guide
Issue boardGitLab source
Guide Developer guide

C++ interface contracts

These are proposed integration boundaries for CORE-001 through CORE-003. Agree the signatures, ownership and errors in a shared MR before parallel feature coding. They describe the design; they are not existing compiled headers.

Shared types

using PageId = std::uint32_t;
using SlotId = std::uint16_t;
struct RID { PageId page; SlotId slot; };

// Nullable storage is reserved so optional NULL does not force a format rewrite.
using Value = std::variant<std::monostate, std::int32_t, double, std::string>;
struct Column {
    std::string name;
    DataType type;               // Int, Float, Varchar
    std::uint32_t max_bytes;     // VARCHAR limit
    bool nullable;
    std::optional<Value> default_value;
};
using Row = std::vector<Value>;
struct Schema { std::vector<Column> columns; /* ordered keys and indexes */ };

Decide INT bounds and exact on-disk encodings explicitly. The presence of a nullable representation does not mean optional NULL SQL semantics are implemented. Use owned strings and rows at module boundaries.

Parser to executor

Statement parse(std::string_view sql);            // owned AST
BoundStatement bind(const Statement&, const Catalog&, const Session&);
Result execute(const BoundStatement&, Engine&);

Statement is a tagged set of required statement structs. A bound column identifies its source table and position; executors do not repeatedly look up names per row. Choose one consistent failure mechanism in CORE-003, such as a typed error value or a typed exception caught at the command boundary.

SQL side to storage side

Interface Inputs Output and lifetime Owner
RecordStore.insert Table handle, validated Row Stable RID Storage
RecordStore.fetch Table handle, RID Owned Row or not-found Storage
RecordStore.scan Table handle Cursor; next returns an owned row and RID Storage
RecordStore.update / erase Stable RID and validated replacement Success or typed I/O/not-found error Storage
Index.find / range Typed ordered key or lower/upper bounds Cursor of candidate RIDs; duplicates retained Storage
Index.insert / erase Key and RID pair One-entry mutation status Storage
Catalog.getSchema Active database, table name Immutable schema view with documented handle lifetime SQL
ConstraintManager.validate Proposed old/new row, schema, engine lookup Accepted mutation or typed rejection SQL
Importer.load Database, table, path Imported row count Shared
WriteCoordinator.apply Validated change and index definitions Consistent row/index state or undo on failure Shared

The SQL owner can test against a small in-memory mock implementing these boundaries. The storage owner can test RecordStore and Index directly without SQL. Those mocks are for module tests, not the submitted database implementation.

Page layer ownership

PageGuard BufferPool::fetch(FileId file, PageId page);
PageId PageFile::allocate();
void BufferPool::flushAll();

PageGuard is move-only RAII: it pins a page until destruction and exposes a way to mark dirty. Pointers into page memory must not escape a guard's lifetime. Record cursors release pages between steps where practical; result storage and joins remain bounded.

Result and error boundary

A Result is one of: a table with column metadata and rows/cursor, affected-row count, empty DDL success, or a typed error. Keep human-readable messages separate from the required diagnostic category. The result writer owns CSV escaping assumptions, two-decimal formatting, DESC layout, separators and flushing.

Integration rules

  1. Change a shared signature only with an updated contract and the other teammate's review.
  2. An MR implements one spec or a small explicitly linked pair; unrelated storage/parser work stays separate.
  3. Declare dependencies using stable spec IDs and issue links.
  4. Validate a write before publishing its row and index changes.
  5. Include a focused module test and the relevant SQL/grader integration evidence.
  6. Never label a task complete because its page exists. Completion requires reviewed working code and passing acceptance checks.
DBS 005 · Specification v1 · Team review required for proposed interfaces.
Engine behavior is planned; implementation progress lives in GitLab.