ToyDB is an educational database implementation inspired by Let's Build a Simple Database, built in Go as a learning project. This implementation provides a hands-on exploration of database internals, from parsing SQL-like commands to managing data storage with B-trees.
- Tokenizer: Breaks input into meaningful tokens
- Parser: Analyzes token sequences to build abstract syntax trees
- Code Generator: Converts parsed statements into executable bytecode
- Virtual Machine: Executes generated bytecode operations
- B-tree: Efficient index structure for data organization
- Pager: Manages memory pages and disk I/O operations
- OS Interface: Abstracts operating system interactions
- Docker and Docker Compose
# Build the development container
docker-compose build toydb-dev
# Start the database shell
docker-compose run --rm toydb-dev
Add new records to the database:
db > insert 1 user1 user1@gmail.com
Executed.
db > insert 2 user2 user2@gmail.com
Executed.
db > insert 3 user3 user3@gmail.com
Executed.
Retrieve all records from the database:
db > select
(1, user1, user1@gmail.com)
(2, user2, user2@gmail.com)
(3, user3, user3@gmail.com)
Executed.
View the internal B-tree structure:
db > .btree
Tree:
- leaf (size 3)
- key 1
- key 2
- key 3
This project serves as a practical implementation for understanding:
- Database query parsing and execution
- B-tree data structures for indexing
- Memory management and paging systems
- Virtual machine design for database operations
- File I/O and persistence mechanisms
Currently supports basic INSERT
and SELECT
operations. The project is actively developed as part of the learning journey in Go programming and database internals.
This is primarily an educational project, but suggestions and improvements are welcome through GitHub issues or pull requests.
JingHuang Su - LinkedIn
Open to new opportunities!