How antoniosarosi/mkdb works
MKDB is a learning-oriented relational database server with a TCP console client. Its main workflow accepts SQL over the network, parses and prepares statements, generates and executes query plans, and persists table/index pages. The README documents the server/client protocol workflow; source-index references and excerpts support the internal relationships shown. Some runtime wiring is unsampled, so uncertain links are omitted or marked unverified.
Main entry points: db.rs Database context · plan.rs Plan execution · statement.rs Statement AST · btree.rs B-tree indexes
Components 24
Client and server
- Console client
client/src/main.rs - TCP server
src/tcp/server.rs - Wire protocol
src/tcp/proto.rs
SQL processing
- SQL parser
src/sql/parser.rs - Tokenizer and tokens
src/sql/tokenizer.rs - Statement AST
src/sql/statement.rs - Semantic analysis
src/sql/analyzer.rs - SQL optimizer
src/sql/optimizer.rs - Statement preparation
src/sql/prepare.rs
Query execution
- Query optimizer
src/query/optimizer.rs - Plan generator
src/query/planner.rs - Plan execution
src/vm/plan.rs - Statement execution
src/vm/statement.rs - Expression evaluation
src/vm/expression.rs
Storage engine
- B-tree indexes
src/storage/btree.rs - Tuple encoding
src/storage/tuple.rs - Slotted pages
src/storage/page.rs - Pager and transactions
src/paging/pager.rs - Page cache
src/paging/cache.rs - Page I/O
src/paging/io.rs
Database support
- Database context
src/db.rs - File access
src/os.rs - Resource pool
src/pool.rs
Other components
- SQL user
Connections 29
- SQL user → Console client: enters SQL
README.md - Console client → TCP server: connects to
README.md - TCP server → Wire protocol: uses protocol
README.md - Wire protocol → Database context: executes requests
src/tcp/proto.rs - Database context → SQL parser: runs SQL pipeline
src/sql/mod.rs - SQL parser → Tokenizer and tokens: consumes tokens
- SQL parser → Statement AST: produces statements
src/sql/parser.rs - Semantic analysis → Statement AST: validates statements
src/sql/analyzer.rs - SQL optimizer → Statement AST: rewrites statements
src/sql/mod.rs - Statement preparation → Statement AST: prepares statements
src/sql/mod.rs - Database context → Semantic analysis: invokes pipeline
src/sql/mod.rs - Database context → SQL optimizer: invokes pipeline
src/sql/mod.rs - Database context → Statement preparation: invokes pipeline
src/sql/mod.rs - Query optimizer → Statement AST: reads statement forms
src/query/optimizer.rs - Query optimizer → Plan execution: builds optimized plans
src/query/optimizer.rs - Plan generator → Query optimizer: uses optimization
src/query/planner.rs - Plan generator → Plan execution: generates plans
src/query/planner.rs - Database context → Plan generator: hands off statements
- Plan execution → Expression evaluation: evaluates expressions
src/vm/plan.rs - Plan execution → B-tree indexes: scans and updates
src/storage/btree.rs - Statement execution → Plan execution: runs plans
src/vm/statement.rs - B-tree indexes → Slotted pages: manipulates pages
src/storage/btree.rs - B-tree indexes → Pager and transactions: accesses pages
src/storage/btree.rs - B-tree indexes → Tuple encoding: encodes keys
src/storage/btree.rs - Pager and transactions → Page cache: caches pages
src/paging/pager.rs - Pager and transactions → Page I/O: reads and writes
src/paging/io.rs - Page cache → Slotted pages: stores page buffers
src/paging/cache.rs - Database context → File access: uses file layer
src/db.rs - Database context → Page cache: uses cache
src/db.rs