MiniDB supports a subset of SQL for data manipulation and definition.
MiniDB currently creates schemas programmatically in main.go for the users table. Dynamic CREATE TABLE via SQL is not yet exposed in the parser.
Schema for users: id (int), name (string).
INSERT
INSERT INTO users VALUES (1, 'alice')
INSERT INTO users VALUES (2, 'bob'), (3, 'charlie')SELECT
SELECT * FROM users
SELECT * FROM users WHERE id = 1
SELECT * FROM users WHERE name = 'alice'SELECT *is the only projected column set supported.WHEREsupports simple equality checks (=).
These are custom extensions to manage the storage engine.
FLUSH -- Flushes MemTable to Disk (SSTable)
COMPACT -- Merges all SSTablesBEGIN
COMMIT
ROLLBACK (or ABORT)-
Parser: The custom recursive-descent parser (
internal/sql/parser) reads the SQL string.- If valid, returns a
Statementnode (e.g.,SelectStmt). - If invalid, returns a syntax error.
- If valid, returns a
-
Binder: The binder (
internal/sql/binder) resolves table and column names against the Catalog.- It converts
Statement(AST) ->LogicalPlan. - Optimization: If a
WHEREclause references an indexed column (e.g.,id), the Binder generates anIndexScanNodeinstead of aSeqScanNode+FilterNode.
- It converts
-
Executor: The logic plan is converted into a tree of physical Iterators.
Next()is called repeatedly on the root iterator.- Each iterator pulls data from its child, processes it (filters, projects), and returns it up the stack.