Relational NT
A relational database kernel shaped around NT-style object management.
Loading...
Searching...
No Matches
VM.h
Go to the documentation of this file.
1#pragma once
2
3#include "Api.h"
4#include "CursorManager.h"
5#include "Types.h"
6
7#include <optional>
8#include <string>
9#include <unordered_set>
10#include <vector>
11
16
17namespace nt {
54
66 struct PathArg {
67 enum class Kind { Var, Const };
68
69 Kind kind;
70 std::string name;
71
72 static PathArg Var(std::string attr) {
73 return {Kind::Var, std::move(attr)};
74 }
75 static PathArg Const(std::string val) {
76 return {Kind::Const, std::move(val)};
77 }
78 };
79
80 enum Operation {
81 FOL_OPERATION_SCAN = 1,
82 FOL_OPERATION_JOIN,
83 FOL_OPERATION_TAKE,
84 FOL_OPERATION_PROJECT,
85 FOL_OPERATION_MATERIALIZE,
86 FOL_OPERATION_RENAME,
87 FOL_OPERATION_UNION
88 };
89
116 struct PlanNode {
117 Operation op;
118 PlanNode* left = nullptr;
119 PlanNode* right = nullptr;
120
127
134 std::vector<PathArg> scan_args;
135
137 std::size_t take_limit = 0;
138 std::size_t take_count = 0;
139
141 std::unordered_set<std::string> project_attrs;
142 std::optional<Tuple> project_buffer;
143
156 Tuple* join_left = nullptr;
157 std::optional<Tuple> join_buffer;
158 std::unordered_set<std::string> join_attrs;
159
167 std::vector<Tuple> mat_buffer;
168 std::size_t mat_pos = 0;
169 bool mat_done = false;
170
172 PlanNode* upstream = nullptr;
173 std::unordered_map<std::string, std::string> attrs;
174
176 std::vector<PlanNode*> nodes;
177 std::vector<PlanNode*>::iterator current_node;
178 };
179
180 class VM {
181 public:
182 // TODO: CursorManager should be injected as a shared runtime instance,
183 // matching the pattern flagged for HandlerManager and LifecycleManager.
184 //
185 // A single CursorManager instance supports multiple simultaneous cursors —
186 // all iteration state lives in each cursor struct, not in the manager.
187 // A JOIN plan, for example, holds two independent cursors (one per SCAN leaf)
188 // and both are driven through the same CursorManager reference.
189 explicit VM(CursorManager& cursors);
190
206 Tuple* Next(PlanNode* node);
207
208 private:
209 CursorManager& cursors_;
210
215 static std::vector<std::string> ResolveArgs(const std::vector<PathArg>& tmpl, Tuple* from);
216
218 static void ResetInner(CursorManager::cursor* c, std::vector<std::string> args);
219
226 void Rewind(PlanNode* node, Tuple* outer);
227
229 static Tuple* MergeInto(PlanNode* node, Tuple* left, Tuple* right);
230 };
231} // namespace nt
Defines symbol visibility for the Relational NT public API.
Declares paging and cursor orchestration for query execution.
Shared enum types and core data types used by the runtime.
Orchestrates paginated data retrieval from a storage backend.
Definition CursorManager.h:36
A single row of data streamed lazily from the cursor layer.
Definition Types.h:136
Tuple * Next(PlanNode *node)
Pulls the next tuple from the plan tree (Tarski/FOL core).
Definition VM.cpp:88
Contains the Relational NT runtime managers and API facade.
Active scan state for a single relation.
Definition CursorManager.h:74
One segment of a parameterized relation path in a SCAN node.
Definition VM.h:66
std::string name
Attribute name to look up (Var), or literal value (Const).
Definition VM.h:70
A node in the Volcano operator tree executed by the Tarski (FOL) runtime.
Definition VM.h:116
std::vector< PlanNode * > nodes
UNION runtime state.
Definition VM.h:176
Tuple * join_left
JOIN runtime state.
Definition VM.h:156
CursorManager::cursor * scan_cursor
SCAN: pre-opened cursor.
Definition VM.h:126
std::vector< PathArg > scan_args
SCAN: argument template for parameterized relations.
Definition VM.h:134
std::size_t take_limit
TAKE: maximum number of tuples to emit before returning nullptr.
Definition VM.h:137
std::size_t take_count
Runtime counter; mutable during execution.
Definition VM.h:138
std::vector< Tuple > mat_buffer
MATERIALIZE runtime state.
Definition VM.h:167
std::unordered_set< std::string > project_attrs
PROJECT: unordered set of attribute names to keep.
Definition VM.h:141
PlanNode * upstream
RENAME runtime state.
Definition VM.h:172