mini-database
View on GitHubOverview
mini-database is a relational database engine I built from scratch in Java. It supports typed columns, CSV-based persistence, a SQL-like query language, two different indexing strategies, and a transaction system with commit/rollback.
Features
-
Typed columns:
INTEGER,DOUBLE,STRING,BOOLEAN, with type enforcement on insert -
SQL-like queries:
SELECT,INSERT,DELETE,UPDATE, withWHEREclauses supportingAND/OR/NOT - Two index types: a HashMap-based index for O(1) equality lookups, and a TreeMap-based index for sorted, range-based queries
- Snapshot-based transactions supporting commit and rollback
- An interactive REPL for querying a table directly from the command line
A Few Design Decisions
Word-boundary-safe keyword parsing.
The query parser originally detected keywords like WHERE and FROM with plain string search, which would break if a table or column name contained the keyword as a substring (a table named nowhere would get misread as having a WHERE clause).
I fixed this with a small regex-based helper that only matches keywords as whole words.
Snapshot-based undo log for transactions. I initially tried storing inverse queries to support rollback, but the logic got complicated fast. The current approach just captures a snapshot of the table's row list before each change and replays those snapshots in reverse order on rollback. I plan to change snapshots to a more efficient method in the future, as the current way is very memory intensive.
Two index types for two access patterns.
A HashMap-based index handles exact-match lookups in O(1) average time, and a TreeMap-based index keeps entries sorted, which allows for range queries via subMap.
Both are built eagerly at construction time.
Current Status
Actively in development.
Current limitations include no support for mixing AND/OR in the same WHERE clause, no NULL support, and indexes that aren't yet persisted to disk.
See the GitHub repo for the full list of limitations and for plans for future updates.