Skip to main content

Optimizer

Struct Optimizer 

Source
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

Source

pub fn new(stats: Arc<StatsManager>) -> Self

Creates a new optimizer with default configuration.

§Arguments
  • stats - Shared statistics manager for cardinality and selectivity estimates
Source

pub fn with_config(stats: Arc<StatsManager>, config: OptimizerConfig) -> Self

Creates a new optimizer with custom configuration.

§Arguments
  • stats - Shared statistics manager
  • config - Custom optimizer configuration
Source

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.

Source

pub fn config(&self) -> &OptimizerConfig

Returns a reference to the current configuration.

Source

pub fn stats(&self) -> &Arc<StatsManager>

Returns a reference to the statistics manager.

Source

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

Source

pub fn estimate_cost(&self, node: &RirNode) -> PlanCost

Estimates the cost of executing a plan node.

Recursively computes cost estimates for the entire plan tree, using statistics when available and falling back to heuristics.

§Arguments
  • node - The plan node to estimate
§Returns

A PlanCost with estimated rows, CPU cost, GPU memory, and transfers

Source

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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,