pub struct Optimizer { /* private fields */ }Expand description
Query optimizer using statistics for cost-based decisions.
The optimizer transforms query plans to improve execution efficiency by applying rewrites like predicate pushdown and using statistics to estimate costs for different plan alternatives.
Implementations§
Source§impl Optimizer
impl Optimizer
Sourcepub fn new(stats: Arc<StatsManager>) -> Self
pub fn new(stats: Arc<StatsManager>) -> Self
Creates a new optimizer with default configuration.
§Arguments
stats- Shared statistics manager for cardinality and selectivity estimates
Sourcepub fn with_config(stats: Arc<StatsManager>, config: OptimizerConfig) -> Self
pub fn with_config(stats: Arc<StatsManager>, config: OptimizerConfig) -> Self
Creates a new optimizer with custom configuration.
§Arguments
stats- Shared statistics managerconfig- Custom optimizer configuration
Sourcepub fn set_schemas(&mut self, schemas: HashMap<RelId, Schema>)
pub fn set_schemas(&mut self, schemas: HashMap<RelId, Schema>)
Sets the schemas for relations.
This information is used by the optimizer to accurately determine column widths during predicate pushdown.
Sourcepub fn config(&self) -> &OptimizerConfig
pub fn config(&self) -> &OptimizerConfig
Returns a reference to the current configuration.
Sourcepub fn optimize(&self, node: RirNode) -> RirNode
pub fn optimize(&self, node: RirNode) -> RirNode
Optimizes an execution plan by applying transformation rules.
Currently applies:
- Predicate pushdown (if enabled)
Future optimizations may include:
- Join reordering based on cardinality estimates
- Projection pushdown
- Common subexpression elimination
§Arguments
node- The plan to optimize
§Returns
An optimized plan that is semantically equivalent to the input
Sourcepub fn estimate_cost(&self, node: &RirNode) -> PlanCost
pub fn estimate_cost(&self, node: &RirNode) -> PlanCost
Sourcepub fn recommend_indexes(&self) -> Vec<RelId>
pub fn recommend_indexes(&self) -> Vec<RelId>
Returns relations that should have indexes built based on access heat.
This is useful for adaptive query processing where frequently accessed relations benefit from index structures.
Sourcepub fn should_use_greedy(&self, node: &RirNode) -> bool
pub fn should_use_greedy(&self, node: &RirNode) -> bool
Returns true if the query involves more relations than the DP threshold.
Used to decide between exhaustive and greedy join ordering algorithms.