Execution Engine
src/execution/ drives PhysicalPlan trees using the Volcano (iterator) model. Every
operator pulls tuples from its children, coordinating closely with transactions,
storage, and expression evaluation.
Core Components
| Component | Role |
|---|---|
PhysicalPlan | Enum covering all physical operators; each implements VolcanoExecutor. |
ExecutionContext | Shared context carrying the catalog, TxnContext, storage engine, and expression helpers. |
TupleStream | Unified scan interface returned by table/index handles. |
Execution Flow
ExecutionEngine::executecallsiniton the root plan (and recursively on children).- The engine loops calling
next, with parents pulling tuples from children. ExecutionContextsupplies transaction snapshots, lock helpers, and expression evaluation per call.- Once
nextreturnsNone, the accumulated results are returned to the caller (CLI, HTTP API, or tests).
Operator Examples
- PhysicalSeqScan – acquires a
table_streamfrom the storage engine, usesScanPrefetchfor batching, and relies onTxnContext::read_visible_tuplefor MVCC. - PhysicalIndexScan – uses
index_stream, tracksinvisible_hits, and notifies the catalog when garbage accumulates. - PhysicalUpdate/PhysicalDelete – call
prepare_row_for_writeto re-validate locks and the latest tuple before invokingapply_update/delete. - PhysicalNestedLoopJoin – showcases the parent/child pull loop and acts as a baseline for more advanced joins.
Interactions
- StorageEngine – all data access goes through handles/streams, keeping execution storage-agnostic.
- Transaction –
TxnContextenforces locking, snapshots, and undo logging; operators never talk toLockManagerdirectly. - Expression –
ExecutionContext::eval_expr/eval_predicateevaluate expressions built by the planner. - Optimizer/Planner – execution honours the plan as-is; all structural choices happen upstream.
Teaching Ideas
- Implement a new operator (e.g.,
PhysicalMergeJoin) to see howExecutionContextsupport generalises. - Add adaptive prefetching inside
PhysicalSeqScanto explore iterator hints. - Enable
RUST_LOG=execution=traceto watch theinit/nextcall sequence during a query.
Further reading: The Volcano Execution Model