pub mod logical;
pub mod optimizer;
pub mod physical;
pub mod plan_tree;
mod pattern;
mod planner;
pub use plan_tree::{plan_tree_from_compiled, PlanTree, PlanTreeNode};
pub use logical::{
Aggregation, Argument, Create, Delete, Expand, Filter, Foreach, Limit, LogicalOp, LogicalPlan,
Merge, NodeByIdSeek, NodeByPointScan, NodeByPropertyRangeScan, NodeByPropertyScan,
NodeByTextScan, NodeScan, OptionalMatch, PathBuild, PlanNodeId, PointPredicate, Projection,
RelByIdSeek, RelByPointScan, RelByPropertyRangeScan, RelByTextScan, Remove, Set, Sort,
SortLimit, TextPredicate, Unwind,
};
pub use optimizer::Optimizer;
pub use physical::{
ArgumentExec, CreateExec, DeleteExec, ExpandExec, FilterExec, ForeachExec, HashAggregationExec,
LimitExec, MergeExec, NodeByIdSeekExec, NodeByLabelScanExec, NodeByPointScanExec,
NodeByPropertyRangeScanExec, NodeByPropertyScanExec, NodeByTextScanExec, NodeScanExec,
OptionalMatchExec, PathBuildExec, PhysicalNodeId, PhysicalOp, PhysicalPlan, ProjectionExec,
RelByIdSeekExec, RelByPointScanExec, RelByPropertyRangeScanExec, RelByTextScanExec, RemoveExec,
SetExec, SortExec, UnwindExec,
};
pub use planner::Planner;
use lora_analyzer::resolved::ResolvedQuery;
use lora_store::GraphStats;
#[derive(Debug, Clone)]
pub struct CompiledQuery {
pub physical: PhysicalPlan,
pub parameters: std::collections::BTreeSet<String>,
pub unions: Vec<CompiledUnionBranch>,
}
#[derive(Debug, Clone)]
pub struct CompiledUnionBranch {
pub all: bool,
pub physical: PhysicalPlan,
}
pub struct Compiler;
impl Compiler {
pub fn compile(query: &ResolvedQuery, stats: &GraphStats) -> CompiledQuery {
let physical = compile_physical(query, stats);
let unions = query
.unions
.iter()
.map(|union_part| {
let branch_query = ResolvedQuery {
clauses: union_part.clauses.clone(),
unions: Vec::new(),
parameters: Default::default(),
};
CompiledUnionBranch {
all: union_part.all,
physical: compile_physical(&branch_query, stats),
}
})
.collect();
CompiledQuery {
physical,
unions,
parameters: query.parameters.clone(),
}
}
}
fn compile_physical(query: &ResolvedQuery, stats: &GraphStats) -> PhysicalPlan {
let mut planner = Planner::with_stats(stats);
let logical = planner.plan(query);
let mut optimizer = Optimizer::new();
let optimized = optimizer.optimize(logical, stats);
optimizer.lower_to_physical(optimized)
}