DevDB is a lightweight, educational database engine written in C++, inspired by SQLite.
It implements a simple B-Tree based storage engine, supporting basic SQL-like operations such as INSERT and SELECT.
- In-memory + disk-based paging system
- B-Tree implementation (leaf + internal nodes)
- Insert and select operations
- Simple SQL-like interface
- Binary search inside leaf nodes
- Persistent storage using file I/O
- Page cache for performance optimization
insert 1 dev dev@example.com
select.exit -> Exit the database
.btree -> Print the B-Tree structure
.constants -> Show internal constants- Pager
Handles reading/writing pages from disk and caching them in memory.
- Table
Represents the database file and root node of the B-Tree.
- Cursor
Tracks position in the table for reading/writing rows.
- B-Tree Structure Leaf Nodes → Store actual rows Internal Nodes → Store keys and child pointers Data Layout
id (uint32) username (32 bytes) email (255 bytes)
PAGE_SIZE = 4096 bytes
gcc main.c -o devdb./devdb mydb.dbdevdb > insert 1 dev dev@mail.com
Executed.devdb > insert 2 john john@mail.com
Executed.devdb > select
(1, dev, dev@mail.com)
(2, john, john@mail.com)- B-Tree Splitting
- Leaf nodes split when full
- Internal nodes split recursively
- Root splits create a new root node
- Persistence
- Data is flushed to disk on .exit
- Pages are lazily loaded (cache miss system)
- Binary search in nodes
- O(log n) insertion and lookup (theoretical)
- Delete operation
- Update operation
- WAL (Write-Ahead Logging)
- Query parser improvements
- Index optimization
- Concurrency support