pub struct QueryOptimizer { /* private fields */ }Expand description
Query optimizer
Implementations§
Source§impl QueryOptimizer
impl QueryOptimizer
pub fn new() -> Self
pub fn initialize(&mut self) -> Result<(), StatisticalError>
Sourcepub fn optimization_rules(&self) -> &[OptimizationRule]
pub fn optimization_rules(&self) -> &[OptimizationRule]
Returns the list of optimization rules currently registered.
Sourcepub fn add_optimization_rule(&mut self, rule: OptimizationRule)
pub fn add_optimization_rule(&mut self, rule: OptimizationRule)
Add an optimization rule if it is not already present.
Sourcepub fn has_rule(&self, rule: &OptimizationRule) -> bool
pub fn has_rule(&self, rule: &OptimizationRule) -> bool
Returns true when the given rule is registered.
Sourcepub fn estimate_cost(&self, operation: &QueryOperation) -> CostModel
pub fn estimate_cost(&self, operation: &QueryOperation) -> CostModel
Estimate the cost of a single query operation based on its type and the amount of data it operates on. Costs are dimensionless weights chosen so that cheaper operations (Filter, Project, Limit) sort before expensive ones (Scan, Join, Aggregate, Sort).
Sourcepub fn optimize_with_cost(
&mut self,
operations: &[QueryOperation],
) -> Result<ExecutionPlan, StatisticalError>
pub fn optimize_with_cost( &mut self, operations: &[QueryOperation], ) -> Result<ExecutionPlan, StatisticalError>
Optimize a sequence of operations by reordering them to minimize total
cost. Uses a simple greedy strategy: estimate each operation’s cost and
execute cheapest-first. The resulting ExecutionPlan is stored on the
optimizer and also returned.
Sourcepub fn get_execution_plan(&self) -> Option<&ExecutionPlan>
pub fn get_execution_plan(&self) -> Option<&ExecutionPlan>
Returns the most recently optimized execution plan, if any.
Sourcepub fn optimize(
&self,
operations: Vec<QueryOperation>,
) -> Result<QueryPlan, StatisticalError>
pub fn optimize( &self, operations: Vec<QueryOperation>, ) -> Result<QueryPlan, StatisticalError>
Optimize a sequence of operations into a QueryPlan.
Applies three rewrite rules:
- Predicate pushdown — filters are moved ahead of joins so rows are reduced before the expensive join.
- Join-type selection — HashJoin is selected when both join inputs are ≥ 1000 rows; NestedLoop when both are < 100; otherwise the caller-supplied join type is retained.
- Limit-last — Limit is always the final step.
After reordering, per-step cost and output row count are estimated using a simple cost model that tracks the running row count through the plan.
Auto Trait Implementations§
impl Freeze for QueryOptimizer
impl RefUnwindSafe for QueryOptimizer
impl Send for QueryOptimizer
impl Sync for QueryOptimizer
impl Unpin for QueryOptimizer
impl UnsafeUnpin for QueryOptimizer
impl UnwindSafe for QueryOptimizer
Blanket Implementations§
§impl<S, A> Aggregate<Result<S, Error>> for Awhere
A: Aggregate<S>,
impl<S, A> Aggregate<Result<S, Error>> for Awhere
A: Aggregate<S>,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more