Skip to main content

lora_compiler/
physical.rs

1use lora_analyzer::symbols::VarId;
2use lora_analyzer::{
3    ResolvedExpr, ResolvedMergeAction, ResolvedPattern, ResolvedPatternPart, ResolvedProjection,
4    ResolvedRemoveItem, ResolvedSetItem, ResolvedSortItem,
5};
6use lora_ast::{Direction, RangeLiteral};
7
8pub type PhysicalNodeId = usize;
9
10#[derive(Debug, Clone)]
11pub struct PhysicalPlan {
12    pub root: PhysicalNodeId,
13    pub nodes: Vec<PhysicalOp>,
14}
15
16#[derive(Debug, Clone)]
17pub enum PhysicalOp {
18    Argument(ArgumentExec),
19    NodeScan(NodeScanExec),
20    NodeByLabelScan(NodeByLabelScanExec),
21    NodeByPropertyScan(NodeByPropertyScanExec),
22    NodeByPropertyRangeScan(NodeByPropertyRangeScanExec),
23    NodeByTextScan(NodeByTextScanExec),
24    NodeByPointScan(NodeByPointScanExec),
25    RelByPropertyRangeScan(RelByPropertyRangeScanExec),
26    RelByTextScan(RelByTextScanExec),
27    RelByPointScan(RelByPointScanExec),
28    Expand(ExpandExec),
29    Filter(FilterExec),
30    Projection(ProjectionExec),
31    Unwind(UnwindExec),
32    HashAggregation(HashAggregationExec),
33    Sort(SortExec),
34    Limit(LimitExec),
35    Create(CreateExec),
36    Merge(MergeExec),
37    Delete(DeleteExec),
38    Set(SetExec),
39    Remove(RemoveExec),
40    OptionalMatch(OptionalMatchExec),
41    PathBuild(PathBuildExec),
42}
43
44#[derive(Debug, Clone)]
45pub struct PathBuildExec {
46    pub input: PhysicalNodeId,
47    pub output: VarId,
48    pub node_vars: Vec<VarId>,
49    pub rel_vars: Vec<VarId>,
50    pub shortest_path_all: Option<bool>,
51}
52
53/// Left-outer-join: for each input row, runs inner sub-plan.
54/// If inner produces nothing, emits one row with nulls for new_vars.
55#[derive(Debug, Clone)]
56pub struct OptionalMatchExec {
57    pub input: PhysicalNodeId,
58    pub inner: PhysicalNodeId,
59    pub new_vars: Vec<VarId>,
60}
61
62#[derive(Debug, Clone)]
63pub struct ArgumentExec;
64
65#[derive(Debug, Clone)]
66pub struct NodeScanExec {
67    pub input: Option<PhysicalNodeId>,
68    pub var: VarId,
69}
70
71#[derive(Debug, Clone)]
72pub struct NodeByLabelScanExec {
73    pub input: Option<PhysicalNodeId>,
74    pub var: VarId,
75    /// Each inner Vec is a disjunctive group (OR). Outer Vec is conjunctive (AND).
76    pub labels: Vec<Vec<String>>,
77}
78
79#[derive(Debug, Clone)]
80pub struct NodeByPropertyScanExec {
81    pub input: Option<PhysicalNodeId>,
82    pub var: VarId,
83    /// Each inner Vec is a disjunctive group (OR). Outer Vec is conjunctive (AND).
84    pub labels: Vec<Vec<String>>,
85    pub key: String,
86    pub value: ResolvedExpr,
87}
88
89#[derive(Debug, Clone)]
90pub struct NodeByPropertyRangeScanExec {
91    pub input: Option<PhysicalNodeId>,
92    pub var: VarId,
93    pub labels: Vec<Vec<String>>,
94    pub key: String,
95    pub lo: Option<ResolvedExpr>,
96    pub lo_inclusive: bool,
97    pub hi: Option<ResolvedExpr>,
98    pub hi_inclusive: bool,
99}
100
101#[derive(Debug, Clone)]
102pub struct NodeByTextScanExec {
103    pub input: Option<PhysicalNodeId>,
104    pub var: VarId,
105    pub labels: Vec<Vec<String>>,
106    pub key: String,
107    pub predicate: crate::logical::TextPredicate,
108    pub query: ResolvedExpr,
109}
110
111#[derive(Debug, Clone)]
112pub struct NodeByPointScanExec {
113    pub input: Option<PhysicalNodeId>,
114    pub var: VarId,
115    pub labels: Vec<Vec<String>>,
116    pub key: String,
117    pub predicate: crate::logical::PointPredicate,
118}
119
120#[derive(Debug, Clone)]
121pub struct RelByPropertyRangeScanExec {
122    pub input: Option<PhysicalNodeId>,
123    pub src: VarId,
124    pub rel: VarId,
125    pub dst: VarId,
126    pub types: Vec<String>,
127    pub direction: Direction,
128    pub key: String,
129    pub lo: Option<ResolvedExpr>,
130    pub lo_inclusive: bool,
131    pub hi: Option<ResolvedExpr>,
132    pub hi_inclusive: bool,
133}
134
135#[derive(Debug, Clone)]
136pub struct RelByTextScanExec {
137    pub input: Option<PhysicalNodeId>,
138    pub src: VarId,
139    pub rel: VarId,
140    pub dst: VarId,
141    pub types: Vec<String>,
142    pub direction: Direction,
143    pub key: String,
144    pub predicate: crate::logical::TextPredicate,
145    pub query: ResolvedExpr,
146}
147
148#[derive(Debug, Clone)]
149pub struct RelByPointScanExec {
150    pub input: Option<PhysicalNodeId>,
151    pub src: VarId,
152    pub rel: VarId,
153    pub dst: VarId,
154    pub types: Vec<String>,
155    pub direction: Direction,
156    pub key: String,
157    pub predicate: crate::logical::PointPredicate,
158}
159
160#[derive(Debug, Clone)]
161pub struct ExpandExec {
162    pub input: PhysicalNodeId,
163    pub src: VarId,
164    pub rel: Option<VarId>,
165    pub dst: VarId,
166    pub types: Vec<String>,
167    pub direction: Direction,
168    pub rel_properties: Option<ResolvedExpr>,
169    pub range: Option<RangeLiteral>,
170}
171
172#[derive(Debug, Clone)]
173pub struct FilterExec {
174    pub input: PhysicalNodeId,
175    pub predicate: ResolvedExpr,
176}
177
178#[derive(Debug, Clone)]
179pub struct ProjectionExec {
180    pub input: PhysicalNodeId,
181    pub distinct: bool,
182    pub items: Vec<ResolvedProjection>,
183    pub include_existing: bool,
184}
185
186#[derive(Debug, Clone)]
187pub struct UnwindExec {
188    pub input: PhysicalNodeId,
189    pub expr: ResolvedExpr,
190    pub alias: VarId,
191}
192
193#[derive(Debug, Clone)]
194pub struct HashAggregationExec {
195    pub input: PhysicalNodeId,
196    pub group_by: Vec<ResolvedProjection>,
197    pub aggregates: Vec<ResolvedProjection>,
198}
199
200#[derive(Debug, Clone)]
201pub struct SortExec {
202    pub input: PhysicalNodeId,
203    pub items: Vec<ResolvedSortItem>,
204    /// Optional upper bound for rows Sort must retain before a parent LIMIT.
205    pub top_k: Option<usize>,
206}
207
208#[derive(Debug, Clone)]
209pub struct LimitExec {
210    pub input: PhysicalNodeId,
211    pub skip: Option<ResolvedExpr>,
212    pub limit: Option<ResolvedExpr>,
213}
214
215#[derive(Debug, Clone)]
216pub struct CreateExec {
217    pub input: PhysicalNodeId,
218    pub pattern: ResolvedPattern,
219}
220
221#[derive(Debug, Clone)]
222pub struct MergeExec {
223    pub input: PhysicalNodeId,
224    pub pattern_part: ResolvedPatternPart,
225    pub actions: Vec<ResolvedMergeAction>,
226}
227
228#[derive(Debug, Clone)]
229pub struct DeleteExec {
230    pub input: PhysicalNodeId,
231    pub detach: bool,
232    pub expressions: Vec<ResolvedExpr>,
233}
234
235#[derive(Debug, Clone)]
236pub struct SetExec {
237    pub input: PhysicalNodeId,
238    pub items: Vec<ResolvedSetItem>,
239}
240
241#[derive(Debug, Clone)]
242pub struct RemoveExec {
243    pub input: PhysicalNodeId,
244    pub items: Vec<ResolvedRemoveItem>,
245}