How ryogrid/samehadadb works
SamehadaDB is a learning-oriented relational database, usable as an embedded library or through a REST server. The principal workflow accepts SQL, parses and plans it, executes relational operators over catalogued tables and indexes, and returns rows. The repository also documents transactions, logging, recovery, checkpointing, and optimizer statistics. Some relationships below rely on README statements or SOURCE INDEX references because their implementation excerpts were not provided; those limits are reflected in the evidence paths.
Main entry points: samehada.go Database API · executors Query operators · log_manager.go Log manager · checkpoint_manager.go Checkpoint manager
Components 21
SQL interfaces
- REST endpoints
server/main.go - Database API
lib/samehada/samehada.go
Query processing
- SQL parser
lib/parser/parser.go - SQL expressions
lib/parser/parser_expressions.go - Simple planner
lib/planner/simple_planner.go - Selinger optimizer
lib/planner/optimizer/selinger_optimizer.go - Query plans
lib/execution/plans - Execution engine
lib/execution/executors/execution_engine.go - Query operators
lib/execution/executors
Catalog and storage
- Table catalog
lib/catalog/table_catalog.go - Optimizer statistics
lib/catalog/statistics.go - Table heap
lib/storage/access/table_heap.go - Indexes
lib/storage/index - Buffer pool
lib/storage/buffer/buffer_pool_manager.go - Disk manager
lib/storage/disk/disk_manager_impl.go
Transactions and recovery
- Transaction manager
lib/storage/access/transaction_manager.go - Lock manager
lib/storage/access/lock_manager.go - Log manager
lib/recovery/log_manager.go - Log recovery
lib/recovery/log_recovery/log_recovery.go - Checkpoint manager
lib/concurrency/checkpoint_manager.go
Other components
- SQL client
Connections 24
- SQL client → Database API: submits SQL
- SQL client → REST endpoints: sends JSON
- REST endpoints → Database API: executes SQL
server/main.go - Database API → SQL parser: parses SQL
lib/samehada/samehada.go - SQL parser → SQL expressions: builds expressions
lib/parser/parser_expressions.go - Database API → Simple planner: plans queries
lib/samehada/samehada.go - Simple planner → Selinger optimizer: optimizes plans
lib/planner/simple_planner.go - Simple planner → Query plans: creates plans
lib/planner/simple_planner.go - Selinger optimizer → Optimizer statistics: uses estimates
lib/planner/optimizer/selinger_optimizer.go - Database API → Execution engine: executes plans
lib/samehada/samehada.go - Execution engine → Query plans: dispatches plans
lib/execution/executors/execution_engine.go - Execution engine → Query operators: creates operators
lib/execution/executors/execution_engine.go - Query operators → Table catalog: accesses metadata
- Query operators → Table heap: scans and modifies
- Query operators → Indexes: uses indexes
- Table catalog → Table heap: manages tables
lib/catalog/table_catalog.go - Transaction manager → Lock manager: coordinates locks
- Transaction manager → Log manager: records transactions
lib/storage/access/transaction_manager.go - Buffer pool → Disk manager: reads and writes pages
lib/storage/buffer/buffer_pool_manager.go - Buffer pool → Log manager: logs page changes
lib/storage/buffer/buffer_pool_manager.go - Log recovery → Log manager: replays log
lib/recovery/log_recovery/log_recovery.go - Checkpoint manager → Transaction manager: blocks transactions
lib/concurrency/checkpoint_manager.go - Checkpoint manager → Buffer pool: flushes pages
lib/concurrency/checkpoint_manager.go - Checkpoint manager → Log manager: flushes log
lib/concurrency/checkpoint_manager.go