pub struct OptimizeProjections {}Expand description
Optimizer rule to prune unnecessary columns from intermediate schemas
inside the LogicalPlan. This rule:
- Removes unnecessary columns that do not appear at the output and/or are not used during any computation step.
- Adds projections to decrease table column size before operators that benefit from a smaller memory footprint at its input.
- Removes unnecessary
LogicalPlan::Projections from theLogicalPlan.
OptimizeProjections is an optimizer rule that identifies and eliminates
columns from a logical plan that are not used by downstream operations.
This can improve query performance and reduce unnecessary data processing.
The rule analyzes the input logical plan, determines the necessary column indices, and then removes any unnecessary columns. It also removes any unnecessary projections from the plan tree.
§Schema, Field Properties, and Metadata Handling
The OptimizeProjections rule preserves schema and field metadata in most optimization scenarios:
Schema-level metadata preservation by plan type:
- Window and Aggregate plans: Schema metadata is preserved
- Projection plans: Schema metadata is preserved per
projection_schema. - Other logical plans: Schema metadata is preserved unless
LogicalPlan::recompute_schemais called on plan types that drop metadata
Field-level properties and metadata: Individual field properties are preserved when fields
are retained in the optimized plan, determined by exprlist_to_fields
and ExprSchemable::to_field.
Field precedence: When the same field appears multiple times, the optimizer
maintains one occurrence and removes duplicates (refer to RequiredIndices::compact()),
preserving the properties and metadata of that occurrence.
Implementations§
Trait Implementations§
Source§impl Debug for OptimizeProjections
impl Debug for OptimizeProjections
Source§impl Default for OptimizeProjections
impl Default for OptimizeProjections
Source§fn default() -> OptimizeProjections
fn default() -> OptimizeProjections
Source§impl OptimizerRule for OptimizeProjections
impl OptimizerRule for OptimizeProjections
Source§fn apply_order(&self) -> Option<ApplyOrder>
fn apply_order(&self) -> Option<ApplyOrder>
ApplyOrder for details. Read moreSource§fn supports_rewrite(&self) -> bool
fn supports_rewrite(&self) -> bool
Source§fn rewrite(
&self,
plan: LogicalPlan,
config: &dyn OptimizerConfig,
) -> Result<Transformed<LogicalPlan>>
fn rewrite( &self, plan: LogicalPlan, config: &dyn OptimizerConfig, ) -> Result<Transformed<LogicalPlan>>
plan to an optimized form, returning Transformed::yes
if the plan was rewritten and Transformed::no if it was not.Auto Trait Implementations§
impl Freeze for OptimizeProjections
impl RefUnwindSafe for OptimizeProjections
impl Send for OptimizeProjections
impl Sync for OptimizeProjections
impl Unpin for OptimizeProjections
impl UnwindSafe for OptimizeProjections
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
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