A from-scratch, educational SQL database implementation written in Rust. Implements core SQL features (parsing, execution, storage) for learning purposes.Inspired by roseduan. Not production-ready, but a fully-functional tour of database internals.
If you like, please give me a star.
Currently, the storage engine is based on memory, and it is only natural to switch to a disk-based storage engine. During development, I implemented a simplified version of the Bitcask storage engine but did not commit it. Readers can consider implementing the Engine trait themselves to enable this SQL database to store data on disk. For beginners, they can implement Bitcask or BTree; for more advanced users, they can implement BPlusTree or LSM-Tree. Later I will implement a BPlusTree storage engine.
All comments are generated by Claude Code. If there are any errors, please point them out.
Next one is "Index support".However, it might only be possible after I graduate or find a better job.
cd src
cargo run --bin server
and then open another terminal
cargo run --bin client
CREATE TABLE table_name (
[ column_name data_type [ column_constraint [...] ] ]
[, ... ]
);
where data_type is:
- BOOLEAN(BOOL): true | false
- FLOAT(DOUBLE)
- INTEGER(INT)
- STRING(TEXT, VARCHAR)
where column_constraint is:
[ NOT NULL | NULL | DEFAULT expr ]INSERT INTO table_name
[ ( column_name [, ...] ) ]
values ( expr [, ...] );SELECT [* | col_name | function [ [ AS ] output_name [, ...] ]]
FROM from_item
[WHERE expr]
[GROUP BY col_name]
[HAVING expr]
[ORDER BY col_name [asc | desc] [, ...]]
[LIMIT count]
[OFFSET count]where function is:
- count(col_name)
- min(col_name)
- max(col_name)
- sum(col_name)
- avg(col_name)
where from_item is:
- table_name
- table_name
join_typetable_name [ONpredicate]
where join_type is:
- cross join
- join
- left join
- right join
where on predicate is:
- column_name = column_name
UPDATE table_name
SET column_name = expr [, ...]
[WHERE condition];
where condition is: `column_name = expr`DELETE FROM table_name
[WHERE condition];
where condition is: `column_name = expr`SHOW TABLESSHOW TABLE `table_name`BEGIN;
COMMIT;
ROLLBACK;
