FlashDB is my attempt to build a relational SQL database from scratch in C++.
I’m building it to understand how databases actually work internally instead of treating a database as a black box.
The architecture is inspired by Edward Sciore’s Database Design and Implementation.
SQL
↓
Lexer
↓
Parser
↓
AST
↓
Planner
↓
Executor
↓
Record Manager
↓
Buffer Manager
↓
File Manager
↓
Disk
- File Manager — manages database files and fixed-size pages.
- Buffer Manager — caches pages in memory and tracks dirty and pinned pages.
- Record Manager — stores, reads, updates, and deletes records.
- Schema — defines table columns and data types.
- Table Catalog — manages table definitions.
- Record Layout — manages field positions and record sizes.
The SQL frontend converts SQL text into tokens, parses them, and builds an AST representing each query.
-- Create a table
CREATE TABLE student (
id INT,
name VARCHAR
);
-- Insert a row
INSERT INTO student VALUES (1, 'Alice');
-- Read rows
SELECT name
FROM student;
-- Filter rows
SELECT name
FROM student
WHERE id = 1;
-- Update rows
UPDATE student
SET name = 'Bob'
WHERE id = 1;
-- Delete rows
DELETE FROM student
WHERE id = 1;DDL — Data Definition
CREATE
TABLE
DML — Data Manipulation
INSERT
INTO
VALUES
UPDATE
SET
DELETE
Query
SELECT
FROM
WHERE
Data Types
INT
VARCHAR
Supported Operators
=
- No joins
- No
ORDER BY - No
GROUP BY - No aggregate functions
- No subqueries
- No index-based query execution
- Limited data types
- Limited expression operators
- Planner — converts SQL ASTs into query plans.
- Executor — executes query plans.
- Operators — provides scans, filters, and projections.
- Transactions — groups database operations into units of work.
- Logging — records changes for durability.
- Recovery — restores database state after failures.
- B+ Tree — planned index structure for efficient lookups.
- Index Manager — manages indexes associated with tables.
- Index Scans — enables indexed query execution.
- Query Optimizer — chooses execution plans.
- Cost Estimation — estimates plan costs.
- Plan Selection — selects an execution strategy.
FlashDB/
├── src/
│ ├── file/
│ ├── log/
│ ├── buffer/
│ ├── tx/
│ ├── record/
│ ├── metadata/
│ ├── parser/
│ ├── planner/
│ ├── query/
│ └── index/
├── tests/
├── docs/
├── CMakeLists.txt
└── README.md
cmake -S . -B build
cmake --build buildctest --test-dir build --output-on-failureFlashDB was initially built as an educational project to understand how SQL and database systems work internally. It has since grown into a working database engine that closely follows the structure and behavior of a real database system.