Phase 1 established the fundamental types and storage primitives required for a modern, type-safe SQL engine.
Transitioned from C-style unions to std::variant.
- Type Safety: Use of
std::getandstd::holds_alternativeprevents invalid memory access. - Null Handling: Explicit
std::monostaterepresentation for SQLNULL. - Operators: Overloaded comparison and arithmetic operators for native SQL expression evaluation.
Implemented a platform-agnostic abstraction for random access I/O.
- Fixed-size Pages: Default 4KB pages matching OS memory pages.
- Atomic Operations: Ensure consistent page-level reads and writes.
Introduced a caching layer to minimize disk I/O.
- Replacement Policy: LRU-K algorithm implementation for intelligent page eviction.
- Thread Safety: Mutex-guarded page table and free list management.
- Pinning: Support for pinning pages in memory during critical operations.
Implemented the physical row storage format.
- Slotted Pages: Header-based layout tracking row offsets and lengths.
- Variable Length Support: Efficient handling of
VARCHARandTEXTdata. - Meta-data Management: In-page tracking of
xmin,xmax, andlsnfor MVCC and recovery.
- Pre-allocating the buffer pool reduces runtime fragmentation.
- Binary compatibility with the previous C implementation was maintained for initial data migration.