Skip to content

devmehtaa/devdb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

DevDB (Relational Database Engine in C++)

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.


Features

  • 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

Supported Commands

SQL-like statements

insert 1 dev dev@example.com
select

Meta commands

.exit        -> Exit the database
.btree       -> Print the B-Tree structure
.constants   -> Show internal constants

Architecture Overview

  1. Pager

Handles reading/writing pages from disk and caching them in memory.

  1. Table

Represents the database file and root node of the B-Tree.

  1. Cursor

Tracks position in the table for reading/writing rows.

  1. B-Tree Structure Leaf Nodes → Store actual rows Internal Nodes → Store keys and child pointers Data Layout

Each row contains:

id (uint32) username (32 bytes) email (255 bytes)

Stored in fixed-size pages:

PAGE_SIZE = 4096 bytes


How to Build

Compile

gcc main.c -o devdb

Run

./devdb mydb.db

Example Usage

devdb > 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)

Design Highlights

  1. B-Tree Splitting
  2. Leaf nodes split when full
  3. Internal nodes split recursively
  4. Root splits create a new root node
  5. Persistence
  6. Data is flushed to disk on .exit
  7. Pages are lazily loaded (cache miss system)
  8. Binary search in nodes
  9. O(log n) insertion and lookup (theoretical)

Future Improvements

  1. Delete operation
  2. Update operation
  3. WAL (Write-Ahead Logging)
  4. Query parser improvements
  5. Index optimization
  6. Concurrency support

About

SQL Engine

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages