pub struct QueryOptimizer { /* private fields */ }Expand description
Orchestrates all optimisation passes over a validated QueryPlan.
The optimizer applies a fixed sequence of logical rewrites (constant folding, predicate pushdown, column pruning) and, when a statistics provider is available, cost-based join reordering.
§Examples
use vlorql_core::optimizer::QueryOptimizer;
use vlorql_core::statistics::DummyStatisticsProvider;
use std::sync::Arc;
let stats = Arc::new(DummyStatisticsProvider::default());
let optimizer = QueryOptimizer::new(stats);Implementations§
Source§impl QueryOptimizer
impl QueryOptimizer
Sourcepub fn new(stats_provider: Arc<dyn StatisticsProvider>) -> Self
pub fn new(stats_provider: Arc<dyn StatisticsProvider>) -> Self
Creates a new optimizer with all rewrite rules enabled.
When stats_provider is a non-empty provider, join reordering is
also enabled. Pass DummyStatisticsProvider::default() to skip
join reordering.
Sourcepub fn rewrites_only() -> Self
pub fn rewrites_only() -> Self
Creates an optimizer with only the logical rewrite rules (no join reordering), regardless of whether statistics are available.
Sourcepub fn with_join_reorder(self, enabled: bool) -> Self
pub fn with_join_reorder(self, enabled: bool) -> Self
Enables or disables join reordering at runtime.
Sourcepub async fn estimated_cost(&self, plan: &QueryPlan) -> Option<Cost>
pub async fn estimated_cost(&self, plan: &QueryPlan) -> Option<Cost>
Returns the estimated cost of executing plan’s join chain.
Returns None when no join reorderer is configured.
Sourcepub fn optimize(&self, plan: &QueryPlan) -> Result<QueryPlan, VlorQLError>
pub fn optimize(&self, plan: &QueryPlan) -> Result<QueryPlan, VlorQLError>
Applies synchronous rewrite rules (constant folding, predicate pushdown, column pruning) to the plan.
Sourcepub fn optimize_repeat(
&self,
plan: &QueryPlan,
max_rounds: usize,
) -> Result<QueryPlan, VlorQLError>
pub fn optimize_repeat( &self, plan: &QueryPlan, max_rounds: usize, ) -> Result<QueryPlan, VlorQLError>
Applies the rewrite pipeline in fixed-point iteration (up to
max_rounds) until the plan stabilizes. See
RewriterPipeline::repeat_until_stable.
Sourcepub async fn optimize_async(
&self,
plan: &QueryPlan,
) -> Result<QueryPlan, VlorQLError>
pub async fn optimize_async( &self, plan: &QueryPlan, ) -> Result<QueryPlan, VlorQLError>
Applies all rewrite rules and, if enabled, cost-based join reordering. This is the async entry point because join reordering consults the statistics provider.
Trait Implementations§
Source§impl Clone for QueryOptimizer
impl Clone for QueryOptimizer
Source§fn clone(&self) -> QueryOptimizer
fn clone(&self) -> QueryOptimizer
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for QueryOptimizer
impl !UnwindSafe for QueryOptimizer
impl Freeze for QueryOptimizer
impl Send for QueryOptimizer
impl Sync for QueryOptimizer
impl Unpin for QueryOptimizer
impl UnsafeUnpin for QueryOptimizer
Blanket Implementations§
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request