pub fn optimize(&mut self) {
        // Optimization memoizes individual `ScalarExpr` expressions that
        // are sure to be evaluated, canonicalizes references to the first
        // occurrence of each, inlines expressions that have a reference
        // count of one, and then removes any expressions that are not
        // referenced.
        self.memoize_expressions();
        self.inline_expressions();
        self.remove_undemanded();

        // Re-build `self` from parts to restore evaluation order invariants.
        let (map, filter, project) = self.as_map_filter_project();
        *self = Self::new(self.input_arity)
            .map(map)
            .filter(filter)
            .project(project);
    }
/// Optimize the internal expression evaluation order.
///
/// This method performs several optimizations that are meant to streamline
/// the execution of the `MapFilterProject` instance, but not to alter its
/// semantics. This includes extracting expressions that are used multiple
/// times, inlining those that are not, and removing expressions that are
/// unreferenced.
///
/// This method will inline all temporal expressions, and remove any columns
/// that are not demanded by the output, which should transform any temporal
/// filters to a state where the temporal expressions exist only in the list
/// of predicates.
///
/// # Example
///
/// This example demonstrates how the re-use of one expression, converting
/// column 1 from a string to an integer, can be extracted and the results
/// shared among the two uses. This example is used for each of the steps
/// along the optimization path.
///
/// ```rust
/// use expr::{func, MapFilterProject, MirScalarExpr, UnaryFunc, BinaryFunc};
/// // Demonstrate extraction of common expressions (here: parsing strings).
/// let mut map_filter_project = MapFilterProject::new(5)
///     .map(vec![
///         MirScalarExpr::column(0).call_unary(UnaryFunc::CastStringToInt64(func::CastStringToInt64)).call_binary(MirScalarExpr::column(1).call_unary(UnaryFunc::CastStringToInt64(func::CastStringToInt64)), BinaryFunc::AddInt64),
///         MirScalarExpr::column(1).call_unary(UnaryFunc::CastStringToInt64(func::CastStringToInt64)).call_binary(MirScalarExpr::column(2).call_unary(UnaryFunc::CastStringToInt64(func::CastStringToInt64)), BinaryFunc::AddInt64),
///     ])
///     .project(vec![3,4,5,6]);
///
/// let mut expected_optimized = MapFilterProject::new(5)
///     .map(vec![
///         MirScalarExpr::column(1).call_unary(UnaryFunc::CastStringToInt64(func::CastStringToInt64)),
///         MirScalarExpr::column(0).call_unary(UnaryFunc::CastStringToInt64(func::CastStringToInt64)).call_binary(MirScalarExpr::column(5), BinaryFunc::AddInt64),
///         MirScalarExpr::column(5).call_binary(MirScalarExpr::column(2).call_unary(UnaryFunc::CastStringToInt64(func::CastStringToInt64)), BinaryFunc::AddInt64),
///     ])
///     .project(vec![3,4,6,7]);
///
/// // Optimize the expression.
/// map_filter_project.optimize();
///
/// assert_eq!(
///     map_filter_project,
///     expected_optimized,
/// );
/// ```
Optimize the internal expression evaluation order.
This method performs several optimizations that are meant to streamline
the execution of the `MapFilterProject` instance, but not to alter its
semantics. This includes extracting expressions that are used multiple
times, inlining those that are not, and removing expressions that are
unreferenced.

This method will inline all temporal expressions, and remove any columns
that are not demanded by the output, which should transform any temporal
filters to a state where the temporal expressions exist only in the list
of predicates.
Optimize the internal expression evaluation order . This method performs several optimizations that are meant to streamline the execution of the ` MapFilterProject ` instance but not to alter its semantics . This includes extracting expressions that are used multiple times inlining those that are not and removing expressions that are unreferenced . This method will inline all temporal expressions and remove any columns that are not demanded by the output which should transform any temporal filters to a state where the temporal expressions exist only in the list of predicates .
pub fn optimize(&mut self) {
        // Optimization memoizes individual `ScalarExpr` expressions that
        // are sure to be evaluated, canonicalizes references to the first
        // occurrence of each, inlines expressions that have a reference
        // count of one, and then removes any expressions that are not
        // referenced.
        self.memoize_expressions();
        self.inline_expressions();
        self.remove_undemanded();
        // Re-build `self` from parts to restore evaluation order invariants.
        let (map, filter, project) = self.as_map_filter_project();
        *self = Self::new(self.input_arity)
            .map(map)
            .filter(filter)
            .project(project);
    }
pub fn optimize ( & mut self ) { // Optimization memoizes individual `ScalarExpr` expressions that // are sure to be evaluated, canonicalizes references to the first // occurrence of each, inlines expressions that have a reference // count of one, and then removes any expressions that are not // referenced. self . memoize_expressions ( ) ; self . inline_expressions ( ) ; self . remove_undemanded ( ) ; // Re-build `self` from parts to restore evaluation order invariants. let ( map , filter , project ) = self . as_map_filter_project ( ) ; * self = Self :: new ( self . input_arity ) . map ( map ) . filter ( filter ) . project ( project ) ; }
Optimize the internal expression evaluation order.
Optimize the internal expression evaluation order .
&mut self
&mut self
example
This example demonstrates how the re-use of one expression, converting
column 1 from a string to an integer, can be extracted and the results
shared among the two uses. This example is used for each of the steps
along the optimization path.

```rust
use expr::{func, MapFilterProject, MirScalarExpr, UnaryFunc, BinaryFunc};
Demonstrate extraction of common expressions (here: parsing strings).
let mut map_filter_project = MapFilterProject::new(5)
.map(vec![
MirScalarExpr::column(0).call_unary(UnaryFunc::CastStringToInt64(func::CastStringToInt64)).call_binary(MirScalarExpr::column(1).call_unary(UnaryFunc::CastStringToInt64(func::CastStringToInt64)), BinaryFunc::AddInt64),
MirScalarExpr::column(1).call_unary(UnaryFunc::CastStringToInt64(func::CastStringToInt64)).call_binary(MirScalarExpr::column(2).call_unary(UnaryFunc::CastStringToInt64(func::CastStringToInt64)), BinaryFunc::AddInt64),
])
.project(vec![3,4,5,6]).

let mut expected_optimized = MapFilterProject::new(5)
.map(vec![
MirScalarExpr::column(1).call_unary(UnaryFunc::CastStringToInt64(func::CastStringToInt64)),
MirScalarExpr::column(0).call_unary(UnaryFunc::CastStringToInt64(func::CastStringToInt64)).call_binary(MirScalarExpr::column(5), BinaryFunc::AddInt64),
MirScalarExpr::column(5).call_binary(MirScalarExpr::column(2).call_unary(UnaryFunc::CastStringToInt64(func::CastStringToInt64)), BinaryFunc::AddInt64),
])
.project(vec![3,4,6,7]).

Optimize the expression.
map_filter_project.optimize().


This example demonstrates how the re - use of one expression converting column 1 from a string to an integer can be extracted and the results shared among the two uses . This example is used for each of the steps along the optimization path . ` ` ` rust use expr :: { func MapFilterProject MirScalarExpr UnaryFunc BinaryFunc } ; Demonstrate extraction of common expressions ( here : parsing strings ) . let mut map_filter_project = MapFilterProject :: new ( 5 ) . map ( vec! [ MirScalarExpr :: column ( 0 ) . call_unary ( UnaryFunc :: CastStringToInt64 ( func :: CastStringToInt64 )) . call_binary ( MirScalarExpr :: column ( 1 ) . call_unary ( UnaryFunc :: CastStringToInt64 ( func :: CastStringToInt64 )) BinaryFunc :: AddInt64 ) MirScalarExpr :: column ( 1 ) . call_unary ( UnaryFunc :: CastStringToInt64 ( func :: CastStringToInt64 )) . call_binary ( MirScalarExpr :: column ( 2 ) . call_unary ( UnaryFunc :: CastStringToInt64 ( func :: CastStringToInt64 )) BinaryFunc :: AddInt64 ) ] ) . project ( vec! [ 3 4 5 6 ] ) . let mut expected_optimized = MapFilterProject :: new ( 5 ) . map ( vec! [ MirScalarExpr :: column ( 1 ) . call_unary ( UnaryFunc :: CastStringToInt64 ( func :: CastStringToInt64 )) MirScalarExpr :: column ( 0 ) . call_unary ( UnaryFunc :: CastStringToInt64 ( func :: CastStringToInt64 )) . call_binary ( MirScalarExpr :: column ( 5 ) BinaryFunc :: AddInt64 ) MirScalarExpr :: column ( 5 ) . call_binary ( MirScalarExpr :: column ( 2 ) . call_unary ( UnaryFunc :: CastStringToInt64 ( func :: CastStringToInt64 )) BinaryFunc :: AddInt64 ) ] ) . project ( vec! [ 3 4 6 7 ] ) . Optimize the expression . map_filter_project . optimize () .