pub struct RewriterPipeline { /* private fields */ }Expand description
Applies an ordered list of PlanRewriters, feeding each rule’s
output into the next.
The pipeline owns its rules as boxed trait objects so heterogeneous rewriters can be combined. Order matters: constant folding, for example, is usually run before pushdown so folded literals can be analyzed as constants.
§Examples
use vlorql_core::optimizer::{ConstantFolding, PlanRewriter, RewriterPipeline};
use vlorql_core::schema::{
BinaryOperator, DataType, Expression, FromClause, Projection, QueryPlan,
};
let plan = QueryPlan {
select: vec![Projection::Expr {
expression: Expression::BinaryOp {
left: Box::new(Expression::Literal { value: 20.into(), data_type: DataType::Int }),
op: BinaryOperator::Add,
right: Box::new(Expression::Literal { value: 5.into(), data_type: DataType::Int }),
},
alias: Some("total".to_owned()),
}],
from: FromClause { table: "t".to_owned(), alias: None },
r#where: None, group_by: None, having: None,
order_by: None, limit: None, offset: None, joins: None, ctes: None, distinct: false, distinct_on: None, set_operation: None,
};
let pipeline = RewriterPipeline::new().with(ConstantFolding);
let rewritten = pipeline.rewrite(&plan).unwrap();
assert_eq!(
rewritten.select[0],
Projection::Expr {
expression: Expression::Literal { value: 25.into(), data_type: DataType::Int },
alias: Some("total".to_owned()),
},
);Implementations§
Source§impl RewriterPipeline
impl RewriterPipeline
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty pipeline. An empty pipeline is the identity rewrite: it returns its input unchanged.
Sourcepub fn with(self, rule: impl PlanRewriter + 'static) -> Self
pub fn with(self, rule: impl PlanRewriter + 'static) -> Self
Appends a rule and returns the pipeline, for builder-style chaining.
Sourcepub fn push(&mut self, rule: impl PlanRewriter + 'static)
pub fn push(&mut self, rule: impl PlanRewriter + 'static)
Appends a rule in place.
Sourcepub fn rewrite(&self, plan: &QueryPlan) -> Result<QueryPlan, VlorQLError>
pub fn rewrite(&self, plan: &QueryPlan) -> Result<QueryPlan, VlorQLError>
Applies every rule in order. If any rule fails, the error is propagated and no further rules run.
Sourcepub fn repeat_until_stable(
&self,
plan: &QueryPlan,
max_rounds: usize,
) -> Result<QueryPlan, VlorQLError>
pub fn repeat_until_stable( &self, plan: &QueryPlan, max_rounds: usize, ) -> Result<QueryPlan, VlorQLError>
Applies the pipeline repeatedly (up to max_rounds times) until the
plan stops changing (fixed point).
Constant folding may expose new pushdown opportunities, and pushdown may enable more column pruning. Running multiple rounds captures these cascading effects. In practice 2–3 rounds are sufficient; the default is 3.
§Examples
use vlorql_core::optimizer::{ConstantFolding, PlanRewriter, RewriterPipeline};
use vlorql_core::schema::{
BinaryOperator, DataType, Expression, FromClause, Projection, QueryPlan,
};
let plan = QueryPlan {
select: vec![Projection::Expr {
expression: Expression::BinaryOp {
left: Box::new(Expression::Literal { value: 20.into(), data_type: DataType::Int }),
op: BinaryOperator::Add,
right: Box::new(Expression::Literal { value: 5.into(), data_type: DataType::Int }),
},
alias: Some("total".to_owned()),
}],
from: FromClause { table: "t".to_owned(), alias: None },
r#where: None, group_by: None, having: None,
order_by: None, limit: None, offset: None, joins: None, ctes: None, distinct: false, distinct_on: None, set_operation: None,
};
let pipeline = RewriterPipeline::new().with(ConstantFolding);
let rewritten = pipeline.repeat_until_stable(&plan, 3).unwrap();
assert_eq!(
rewritten.select[0],
Projection::Expr {
expression: Expression::Literal { value: 25.into(), data_type: DataType::Int },
alias: Some("total".to_owned()),
},
);Trait Implementations§
Source§impl Debug for RewriterPipeline
impl Debug for RewriterPipeline
Source§impl Default for RewriterPipeline
impl Default for RewriterPipeline
Source§fn default() -> RewriterPipeline
fn default() -> RewriterPipeline
Auto Trait Implementations§
impl !RefUnwindSafe for RewriterPipeline
impl !UnwindSafe for RewriterPipeline
impl Freeze for RewriterPipeline
impl Send for RewriterPipeline
impl Sync for RewriterPipeline
impl Unpin for RewriterPipeline
impl UnsafeUnpin for RewriterPipeline
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> 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