# cstack/db_tutorial

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/cstack-db-tutorial).**

10,464 stars · 1,029 forks · C · MIT

## Links

- GitHub: https://github.com/cstack/db_tutorial
- Homepage: https://cstack.github.io/db_tutorial
- awesome-repositories: https://awesome-repositories.com/repository/cstack-db-tutorial.md

## Topics

`database`

## Description

This project is an educational implementation of a relational database engine written in C. It functions as a SQLite clone, demonstrating the internal mechanics of a database system through a C-based systems project that focuses on manual memory management and file I/O.

The engine is distinguished by its use of a bytecode virtual machine, which executes database operations by compiling SQL statements into low-level instructions. It utilizes a B-tree database engine to organize records in a balanced tree structure, ensuring efficient insertion, search, and range scanning.

The system covers core database internals, including SQL compilation workflows, disk-based persistence, and B-tree indexing with recursive node traversal and node splitting. It also implements data cursor management for navigating result sets.

## Tags

### Data & Databases

- [Relational Database Engines](https://awesome-repositories.com/f/data-databases/relational-database-engines.md) — Implements a complete relational database engine from scratch, including storage, indexing, and query execution.
- [Disk-Persistent Data Structures](https://awesome-repositories.com/f/data-databases/disk-persistent-data-structures.md) — Implements disk-persistent data structures that map the B-Tree directly to a binary file for durability. ([source](https://cstack.github.io/db_tutorial/))
- [Educational Database Systems](https://awesome-repositories.com/f/data-databases/relational-database-management-systems/educational-database-systems.md) — Designed as an educational project to demonstrate the internal mechanics of relational databases and storage engines.
- [SQL-to-Bytecode Compilation](https://awesome-repositories.com/f/data-databases/sql-generators/deferred-query-compilation/sql-string-compilations/sql-to-bytecode-compilation.md) — Translates SQL text into a custom bytecode format for execution by a virtual machine.
- [SQLite Clones](https://awesome-repositories.com/f/data-databases/sqlite-clones.md) — Implements a relational database engine in C that clones the SQLite architecture from scratch.
- [B-Tree](https://awesome-repositories.com/f/data-databases/storage-engines/b-tree.md) — Implements a B-Tree storage system that maps data directly to a binary file for durable disk-based storage.
- [Cursor-Based Iteration](https://awesome-repositories.com/f/data-databases/cursor-based-iteration.md) — Implements cursors for traversing and iterating through records within the storage engine.
- [Single-File Persistence](https://awesome-repositories.com/f/data-databases/key-value-stores/single-file-persistence.md) — Encapsulates the entire database system and its data within a single portable binary file.
- [SQL Statement Parsing](https://awesome-repositories.com/f/data-databases/sql-statement-parsing.md) — Translates SQL text into an internal bytecode representation through a parsing phase.
- [Node Splitting](https://awesome-repositories.com/f/data-databases/storage-engines/b-tree/node-splitting.md) — Maintains B-Tree balance by dividing full nodes and updating parent pointers during data insertion.
- [Recursive Search Traversals](https://awesome-repositories.com/f/data-databases/storage-engines/b-tree/recursive-search-traversals.md) — Provides recursive tree traversal logic to navigate from the root node down to the leaf nodes for record lookup.

### Operating Systems & Systems Programming

- [C Systems Programming](https://awesome-repositories.com/f/operating-systems-systems-programming/c-systems-programming.md) — Written in C with a focus on manual memory management and direct file I/O for database internals.
- [Manual Memory Management](https://awesome-repositories.com/f/operating-systems-systems-programming/manual-memory-management.md) — Employs explicit memory allocation and deallocation in C to precisely control on-disk data layout.
- [Systems Implementation Projects](https://awesome-repositories.com/f/operating-systems-systems-programming/systems-implementation-projects.md) — A low-level implementation focusing on manual memory management and file I/O to build database internals.

### Programming Languages & Runtimes

- [Source-to-Bytecode Compilers](https://awesome-repositories.com/f/programming-languages-runtimes/bytecode-compiled-languages/source-to-bytecode-compilers.md) — Translates structured SQL text into low-level executable bytecode for the virtual machine.
- [Bytecode Virtual Machines](https://awesome-repositories.com/f/programming-languages-runtimes/bytecode-virtual-machines.md) — Provides a custom bytecode virtual machine to execute compiled SQL instructions.

### Scientific & Mathematical Computing

- [Database Implementations](https://awesome-repositories.com/f/scientific-mathematical-computing/data-structure-implementations/educational-implementations/database-implementations.md) — Provides a step-by-step implementation of a database to demonstrate SQL compilation and disk persistence.
- [B-Tree Traversals](https://awesome-repositories.com/f/scientific-mathematical-computing/recursive-tree-traversal-algorithms/b-tree-traversals.md) — Implements recursive traversal from root to leaf nodes to locate specific keys or ranges.
