Mini DB is an educational, relational database built from scratch in C++17. The primary goal is to provide a clean, understandable implementation of core database concepts such as storage management, SQL parsing, and query execution.
- Slotted Page Storage: Professional page layout with a slot directory for efficient variable-length record management.
- SQL Interface: Supports core SQL operations:
CREATE TABLEwithINTandTEXTtypes.INSERT INTOrecords.SELECT *with optionalWHEREfilters andJOIN.DELETErecords with space reclamation support.UPDATEexisting records.
- Indexing:
- Hash Index: O(1) equality lookups for fast retrieval.
- B-Tree Index: Ordered indexing supporting range queries (
>,<,>=,<=).
- Networking: TCP Client/Server architecture for remote SQL execution.
- Persistence: Fixed-size 4KB pages in a single database file; table schemas persist across restarts.
- Robust Testing: 100+ unit and integration tests using GoogleTest.
- Benchmarking: Built-in utility to compare scan vs. index performance.
Mini DB follows a clean layered architecture:
- Storage (
src/storage/): Manages the Pager (File I/O), Page layout (Slotted Pages), and Record serialization. - Catalog (
src/catalog/): Handles metadata, table schemas, and persistence of definitions. - Parser (
src/parser/): A custom Lexer and recursive-descent Parser that converts SQL strings into an AST. - Execution (
src/execution/): A dispatcher that bridges the Parser and Storage/Catalog layers to run queries. - Network (
src/network/): TCP server/client implementation for remote interactions. - REPL (
src/repl/): An interactive command-line shell.
- CMake (3.14+)
- C++17 Compatible Compiler (GCC 7+, Clang 5+)
- Git
# Clone the repository (if not already done)
git clone <repo-url>
cd database
# Configure and build
cmake -S . -B build
cmake --build build -j$(nproc)ctest --test-dir build --output-on-failure./build/src/minidb_repl# Start the server in one terminal
./build/src/minidb_server
# Connect using the client in another terminal
./build/src/minidb_client 127.0.0.1 "SELECT * FROM users;"-- Create a table
CREATE TABLE users (id INT, name TEXT);
-- Create an index for fast lookups
CREATE INDEX id_idx ON users (id);
-- Insert data
INSERT INTO users VALUES (1, 'Alice');
INSERT INTO users VALUES (2, 'Bob');
-- Query with filtering
SELECT * FROM users WHERE id = 1;
-- Update data
UPDATE users SET name = 'Alicia' WHERE id = 1;
-- Relational Join
CREATE TABLE orders (order_id INT, user_id INT);
INSERT INTO orders VALUES (101, 1);
SELECT * FROM users JOIN orders ON users.id = orders.user_id;
-- Delete data
DELETE FROM users WHERE id = 2;- Milestone 1-7: Core Engine (Pager to REPL)
- Milestone 8: Catalog Persistence
- Milestone 9: Basic Indexing (Hash)
- Milestone 10: Extensive Testing & Benchmarking
- Milestone 11: Networking
- Milestone 12: B-Tree Indexes (Range Queries)
- Milestone 13: Slotted Pages
- Milestone 14: UPDATE & Joins
- Milestone 15: Transactions & WAL (Future)
- Milestone 16: Aggregations (Future)
This project is for educational purposes.