pub fn action(&self, relation: &mut MirRelationExpr) {
        if let MirRelationExpr::Reduce {
            input,
            group_key,
            aggregates,
            monotonic: _,
            expected_group_size: _,
        } = relation
        {
            if let MirRelationExpr::Reduce {
                input: inner_input,
                group_key: inner_group_key,
                aggregates: inner_aggregates,
                monotonic: _,
                expected_group_size: _,
            } = &mut **input
            {
                // Collect all columns referenced by outer
                let mut outer_cols = vec![];
                for expr in group_key.iter() {
                    expr.visit_post(&mut |e| {
                        if let MirScalarExpr::Column(i) = e {
                            outer_cols.push(*i);
                        }
                    });
                }

                // We can fuse reduce operators as long as the outer one doesn't
                // group by an aggregation performed by the inner one.
                if outer_cols.iter().any(|c| *c >= inner_group_key.len()) {
                    return;
                }

                if aggregates.is_empty() && inner_aggregates.is_empty() {
                    // Replace inner reduce with map + project (no grouping)
                    let mut outputs = vec![];
                    let mut scalars = vec![];

                    let arity = inner_input.arity();
                    for e in inner_group_key {
                        if let MirScalarExpr::Column(i) = e {
                            outputs.push(*i);
                        } else {
                            outputs.push(arity + scalars.len());
                            scalars.push(e.clone());
                        }
                    }

                    **input = inner_input.take_dangerous().map(scalars).project(outputs);
                }
            }
        }
    }
/// Fuses reduce operators with parent operators if possible.
Fuses reduce operators with parent operators if possible.
Fuses reduce operators with parent operators if possible .
pub fn action(&self, relation: &mut MirRelationExpr) {
        if let MirRelationExpr::Reduce {
            input,
            group_key,
            aggregates,
            monotonic: _,
            expected_group_size: _,
        } = relation
        {
            if let MirRelationExpr::Reduce {
                input: inner_input,
                group_key: inner_group_key,
                aggregates: inner_aggregates,
                monotonic: _,
                expected_group_size: _,
            } = &mut **input
            {
                // Collect all columns referenced by outer
                let mut outer_cols = vec![];
                for expr in group_key.iter() {
                    expr.visit_post(&mut |e| {
                        if let MirScalarExpr::Column(i) = e {
                            outer_cols.push(*i);
                        }
                    });
                }
                // We can fuse reduce operators as long as the outer one doesn't
                // group by an aggregation performed by the inner one.
                if outer_cols.iter().any(|c| *c >= inner_group_key.len()) {
                    return;
                }
                if aggregates.is_empty() && inner_aggregates.is_empty() {
                    // Replace inner reduce with map + project (no grouping)
                    let mut outputs = vec![];
                    let mut scalars = vec![];
                    let arity = inner_input.arity();
                    for e in inner_group_key {
                        if let MirScalarExpr::Column(i) = e {
                            outputs.push(*i);
                        } else {
                            outputs.push(arity + scalars.len());
                            scalars.push(e.clone());
                        }
                    }
                    **input = inner_input.take_dangerous().map(scalars).project(outputs);
                }
            }
        }
    }
pub fn action ( & self , relation : & mut MirRelationExpr ) { if let MirRelationExpr :: Reduce { input , group_key , aggregates , monotonic : _ , expected_group_size : _ , } = relation { if let MirRelationExpr :: Reduce { input : inner_input , group_key : inner_group_key , aggregates : inner_aggregates , monotonic : _ , expected_group_size : _ , } = & mut * * input { // Collect all columns referenced by outer let mut outer_cols = vec ! [ ] ; for expr in group_key . iter ( ) { expr . visit_post ( & mut | e | { if let MirScalarExpr :: Column ( i ) = e { outer_cols . push ( * i ) ; } } ) ; } // We can fuse reduce operators as long as the outer one doesn't // group by an aggregation performed by the inner one. if outer_cols . iter ( ) . any ( | c | * c >= inner_group_key . len ( ) ) { return ; } if aggregates . is_empty ( ) && inner_aggregates . is_empty ( ) { // Replace inner reduce with map + project (no grouping) let mut outputs = vec ! [ ] ; let mut scalars = vec ! [ ] ; let arity = inner_input . arity ( ) ; for e in inner_group_key { if let MirScalarExpr :: Column ( i ) = e { outputs . push ( * i ) ; } else { outputs . push ( arity + scalars . len ( ) ) ; scalars . push ( e . clone ( ) ) ; } } * * input = inner_input . take_dangerous ( ) . map ( scalars ) . project ( outputs ) ; } } } }
Fuses reduce operators with parent operators if possible.
Fuses reduce operators with parent operators if possible .
&self
relation
&mut MirRelationExpr
&self
relation
&mut MirRelationExpr