1pub mod logical;
2pub mod optimizer;
3pub mod physical;
4pub mod plan_tree;
5
6mod pattern;
7mod planner;
8
9pub use plan_tree::{plan_tree_from_compiled, PlanTree, PlanTreeNode};
10
11pub use logical::{
12 Aggregation, Argument, Create, Delete, Expand, Filter, Foreach, Limit, LogicalOp, LogicalPlan,
13 Merge, NodeByPointScan, NodeByPropertyRangeScan, NodeByPropertyScan, NodeByTextScan, NodeScan,
14 OptionalMatch, PathBuild, PlanNodeId, PointPredicate, Projection, RelByPointScan,
15 RelByPropertyRangeScan, RelByTextScan, Remove, Set, Sort, TextPredicate, Unwind,
16};
17pub use optimizer::Optimizer;
18pub use physical::{
19 ArgumentExec, CreateExec, DeleteExec, ExpandExec, FilterExec, ForeachExec, HashAggregationExec,
20 LimitExec, MergeExec, NodeByLabelScanExec, NodeByPointScanExec, NodeByPropertyRangeScanExec,
21 NodeByPropertyScanExec, NodeByTextScanExec, NodeScanExec, OptionalMatchExec, PathBuildExec,
22 PhysicalNodeId, PhysicalOp, PhysicalPlan, ProjectionExec, RelByPointScanExec,
23 RelByPropertyRangeScanExec, RelByTextScanExec, RemoveExec, SetExec, SortExec, UnwindExec,
24};
25pub use planner::Planner;
26
27use lora_analyzer::resolved::ResolvedQuery;
28use lora_store::GraphStats;
29
30#[derive(Debug, Clone)]
31pub struct CompiledQuery {
32 pub physical: PhysicalPlan,
33 pub unions: Vec<CompiledUnionBranch>,
35}
36
37#[derive(Debug, Clone)]
38pub struct CompiledUnionBranch {
39 pub all: bool,
41 pub physical: PhysicalPlan,
42}
43
44pub struct Compiler;
45
46impl Compiler {
47 pub fn compile(query: &ResolvedQuery, stats: &GraphStats) -> CompiledQuery {
53 let physical = compile_physical(query, stats);
54 let unions = query
55 .unions
56 .iter()
57 .map(|union_part| {
58 let branch_query = ResolvedQuery {
59 clauses: union_part.clauses.clone(),
60 unions: Vec::new(),
61 };
62 CompiledUnionBranch {
63 all: union_part.all,
64 physical: compile_physical(&branch_query, stats),
65 }
66 })
67 .collect();
68
69 CompiledQuery { physical, unions }
70 }
71}
72
73fn compile_physical(query: &ResolvedQuery, stats: &GraphStats) -> PhysicalPlan {
74 let mut planner = Planner::with_stats(stats);
75 let logical = planner.plan(query);
76
77 let mut optimizer = Optimizer::new();
78 let optimized = optimizer.optimize(logical, stats);
79
80 optimizer.lower_to_physical(optimized)
82}