Skip to content

About

A persistent, disk-backed B-Tree database engine built from scratch in C.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C-Based SQLite Clone

A lightweight, disk-backed relational database engine built from scratch in C. This project is a portfolio-grade implementation of a database system that demonstrates core database concepts like indexing, memory management, and crash recovery.

Architecture Highlights

  • B-Tree Data Structure: Implements a multi-level B-Tree for efficient indexing, inserting, and deleting of records.
  • Pager: Custom memory management system for caching database pages in memory (dirty pages) and flushing them to disk.
  • Write-Ahead Log (WAL): Ensures crash recovery and ACID-like durability. Operations are logged before being written to the main database file, allowing restoration of state in the event of a power failure or crash.

Build Instructions

To compile the project, use the provided Makefile:

make all

This will produce an executable named db. To run the database engine, provide a database file name:

./db mydb.db

Supported Commands

The database engine supports the following commands:

  • insert <id> <username> <email>: Inserts a new row into the database.
  • select: Retrieves and prints all rows from the database.
  • update <id> <new_username> <new_email>: Updates the username and email of an existing row by ID.
  • delete <id>: Deletes a row from the database by ID.

Meta-commands

  • .exit: Cleanly flushes the state to disk and exits the database REPL.
  • .btree: Prints the internal structure of the B-Tree for debugging purposes.

Known Limitations & Future Roadmap

While this engine successfully implements a persistent, crash-safe B-Tree, it is currently an educational prototype with the following architectural boundaries:

  • Fixed Cache Size (100 Pages): The Pager memory is currently constrained to a hard-coded array of 100 pages. To support databases larger than 400KB in a production environment, the next step is implementing a dynamic cache with a Least Recently Used (LRU) eviction policy to flush untouched pages back to disk.
  • Single-Table Architecture: The engine currently assumes a single table rooted at Page 0. Supporting multiple tables requires building a "System Catalog" (similar to sqlite_master) to map dynamic string table names to their respective root page locations.

About

A persistent, disk-backed B-Tree database engine built from scratch in C.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages