Exemple #1
0
        protected override BoundRelation RewriteGroupByAndAggregationRelation(BoundGroupByAndAggregationRelation node)
        {
            var aggregates = RemoveUnusedSlots(node.Aggregates, a => a.Output);

            node = node.Update(node.Input, node.Groups, aggregates);

            _recorder.Record(node.Aggregates);
            _recorder.Record(node.Groups);

            return(base.RewriteGroupByAndAggregationRelation(node));
        }
Exemple #2
0
        private BoundRelation PushOverGroupByAndAggregation(BoundFilterRelation node, BoundGroupByAndAggregationRelation input)
        {
            // TODO: This may not be that easy.
            //
            // For example this condition can be pushed:
            //
            //      GroupCol = Value
            //
            //  while this can't:
            //
            //      GroupCol = Value OR Func(const) = const
            //
            // Formally, a predicate can be pushed over an aggregate if and only if all disjuncts of the predicate's
            // CNF do reference at least one grouping column.

            BoundExpression remainder = null;
            BoundExpression pushed    = null;

            foreach (var conjunction in Expression.SplitConjunctions(node.Condition))
            {
                if (conjunction.DependsOnAny(input.GetDefinedValues()))
                {
                    remainder = Expression.And(remainder, conjunction);
                }
                else
                {
                    pushed = Expression.And(pushed, conjunction);
                }
            }

            var newInputInput = pushed == null
                ? input.Input
                : new BoundFilterRelation(input.Input, pushed);

            var newInput = RewriteRelation(input.Update(newInputInput, input.Groups, input.Aggregates));

            var newNode = remainder == null
                ? newInput
                : new BoundFilterRelation(newInput, remainder);

            return(newNode);
        }