public override Expression Translate(Expression expression)
 {
     expression = OrderByRewriter.Rewrite(expression);
     expression = base.Translate(expression);
     expression = UnusedColumnRemover.Remove(expression);
     return(expression);
 }
Beispiel #2
0
        public static Expression Optimize(Expression expression, Type typeForEnums, bool simplerPartialVal = true)
        {
            expression = ObjectOperandComparisonExpander.Expand(expression);
            expression = EnumTypeNormalizer.Normalize(expression, typeForEnums);
            expression = GroupByCollator.Collate(expression);
            expression = AggregateSubqueryRewriter.Rewrite(expression);
            expression = UnusedColumnRemover.Remove(expression);
            expression = RedundantColumnRemover.Remove(expression);
            expression = RedundantSubqueryRemover.Remove(expression);
            expression = FunctionCoalescer.Coalesce(expression);
            expression = ExistsSubqueryOptimizer.Optimize(expression);
            expression = RedundantBinaryExpressionsRemover.Remove(expression);

            if (simplerPartialVal)
            {
                expression = Evaluator.PartialEval(expression, c => c.NodeType != (ExpressionType)SqlExpressionType.ConstantPlaceholder && Evaluator.CanBeEvaluatedLocally(c));
            }
            else
            {
                expression = Evaluator.PartialEval(expression);
            }

            expression = RedundantFunctionCallRemover.Remove(expression);
            expression = ConditionalEliminator.Eliminate(expression);
            expression = SqlExpressionCollectionOperationsExpander.Expand(expression);
            expression = SumAggregatesDefaultValueCoalescer.Coalesce(expression);
            expression = OrderByRewriter.Rewrite(expression);

            return(expression);
        }
Beispiel #3
0
        public override System.Linq.Expressions.Expression Translate(Expression expression)
        {
            expression = OrderByRewriter.Rewrite(expression);

            expression = UnusedColumnRemover.Remove(expression);
            expression = RedundantColumnRemover.Remove(expression);
            expression = RedundantSubqueryRemover.Remove(expression);

            var rewritten = CrossApplyRewriter.Rewrite(expression);

            rewritten = CrossJoinRewriter.Rewrite(rewritten);

            if (rewritten != expression)
            {
                expression = rewritten;
                expression = UnusedColumnRemover.Remove(expression);
                expression = RedundantSubqueryRemover.Remove(expression);
                expression = RedundantJoinRemover.Remove(expression);
                expression = RedundantColumnRemover.Remove(expression);
            }


            expression = SkipToRowNumberRewriter.Rewrite(expression);
            expression = OrderByRewriter.Rewrite(expression);
            return(expression);
        }
 public override Expression Translate(Expression expression)
 {
     expression = OrderByRewriter.Rewrite(expression);
     expression = base.Translate(expression);
     expression = SkipToRowNumberRewriter.Rewrite(expression);
     expression = OrderByRewriter.Rewrite(expression);
     return(expression);
 }
Beispiel #5
0
 public override Expression Translate(Expression expression)
 {
     // fix up any order-by's
     expression = OrderByRewriter.Rewrite(Language, expression);
     expression = base.Translate(expression);
     expression = UnusedColumnRemover.Remove(expression);
     //expression = DistinctOrderByRewriter.Rewrite(expression);
     return(expression);
 }
Beispiel #6
0
 public override Expression Translate(Expression expression)
 {
     // fix up any order-by's
     expression = OrderByRewriter.Rewrite(Language, expression);
     expression = base.Translate(expression);
     expression = SkipToNestedOrderByRewriter.Rewrite(Language, expression);
     expression = OrderByRewriter.Rewrite(Language, expression);
     expression = UnusedColumnRemover.Remove(expression);
     expression = RedundantSubqueryRemover.Remove(expression);
     expression = ScalarSubqueryRewriter.Rewrite(Language, expression);
     return(expression);
 }
            public override Expression Translate(Expression expression)
            {
                bool hasRowNumberExpression;

                // fix up any order-by's
                expression = OrderByRewriter.Rewrite(this.Language, expression);

                expression = XmlToCursorExpressionRewriter.Rewrite(expression);

                // remove redundant layers again before cross apply rewrite
                expression = UnusedColumnRemover.Remove(expression);
                expression = RedundantColumnRemover.Remove(expression);
                expression = RedundantSubqueryRemover.Remove(expression);

                expression = OneBasedIndexRewriter.Rewrite(expression);

                // convert cross-apply and outer-apply joins into inner & left-outer-joins if possible
                var rewritten = CrossApplyRewriter.Rewrite(this.language, expression);

                // convert cross joins into inner joins
                rewritten = CrossJoinRewriter.Rewrite(rewritten);

                if (rewritten != expression)
                {
                    expression = rewritten;
                    // do final reduction
                    expression = UnusedColumnRemover.Remove(expression);
                    expression = RedundantSubqueryRemover.Remove(expression);
                    expression = RedundantJoinRemover.Remove(expression);
                    expression = RedundantColumnRemover.Remove(expression);
                }

                // convert skip/take info into RowNumber pattern
                expression = SkipToRowNumberRewriter.Rewrite(expression, out hasRowNumberExpression);

                expression = SkipToNestedOrderByRewriter.Rewrite(this.Language, expression);

                expression = UnusedColumnRemover.Remove(expression);

                expression = WhereCountComparisonRewriter.Rewrite(expression);

                if (!hasRowNumberExpression)
                {
                    expression = OrderByRewriter.Rewrite(this.Language, expression);
                    expression = RedundantSubqueryRemover.Remove(expression);
                }

                expression = VfpCrossJoinIsolator.Isolate(expression);
                expression = ConditionalImmediateIfNullRemover.Remove(expression);
                expression = XmlToCursorJoinRewriter.Rewrite(expression);

                return(expression);
            }
            public override Expression Translate(Expression expression)
            {
                // fix up any order-by's
                expression = OrderByRewriter.Rewrite(this.Language, expression);

                expression = base.Translate(expression);

                //expression = SkipToNestedOrderByRewriter.Rewrite(expression);
                expression = UnusedColumnRemover.Remove(expression);

                return(expression);
            }
Beispiel #9
0
 public override Expression Translate(Expression expression)
 {
     // fix up any order-by's
     expression = OrderByRewriter.Rewrite(expression);
     expression = base.Translate(expression);
     expression = CrossJoinIsolator.Isolate(expression);
     expression = ThreeTopPagerRewriter.Rewrite(expression);
     expression = OrderByRewriter.Rewrite(expression);
     expression = UnusedColumnRemover.Remove(expression);
     expression = RedundantColumnRemover.Remove(expression);
     return(expression);
 }
Beispiel #10
0
        public override Expression Translate(Expression expression)
        {
            // fix up any order-by's
            expression = OrderByRewriter.Rewrite(this.Language, expression);
            expression = base.Translate(expression);

            // convert skip/take info into RowNumber pattern
            expression = SkipToRowNumberRewriter.Rewrite(this.Language, expression);

            // fix up any order-by's we may have changed
            expression = OrderByRewriter.Rewrite(this.Language, expression);

            return(expression);
        }
Beispiel #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        public override Expression Translate(Expression expression)
        {
            // fix up any order-by's
            expression = OrderByRewriter.Rewrite(expression);

            expression = base.Translate(expression);

            // convert skip/take info into RowNumber pattern
            expression = SkipRewriter.Rewrite(expression, Nequeo.Data.DataType.ConnectionContext.ConnectionDataType.OracleDataType);

            // fix up any order-by's we may have changed
            expression = OrderByRewriter.Rewrite(expression);

            return(expression);
        }
        public override Expression Translate(Expression expression)
        {
            // fix up any order-by's
            expression = OrderByRewriter.Rewrite(expression);

            expression = base.Translate(expression);

            expression = ThreeTopPagerRewriter.Rewrite(expression);
            expression = OrderByRewriter.Rewrite(expression);
            expression = UnusedColumnRemover.Remove(expression);
            expression = RedundantSubqueryRemover.Remove(expression);

            expression = ScalarSubqueryRewriter.Rewrite(expression);
            return(expression);
        }
 internal Expression Translate(Expression expression)
 {
     if (expression is ProjectionExpression projection)
     {
         return(projection);
     }
     expression = Evaluator.PartialEval(expression, CanBeEvaluatedLocally);
     expression = QueryBinder.Bind(this, expression);
     expression = ConstantEscaper.EscapeConstants(expression);
     expression = OrderByRewriter.Rewrite(expression);
     expression = RedundantSubqueryRemover.Remove(expression);
     expression = UnusedColumnRemover.Remove(expression);
     expression = AggregateSimplifier.Simplify(expression);
     return(expression);
 }
        private Expression Translate(Expression expression)
        {
            var rootQueryable = new RootQueryableFinder().Find(expression);
            var elementType   = ((IQueryable)((ConstantExpression)rootQueryable).Value).ElementType;

            expression = PartialEvaluator.Evaluate(expression, CanBeEvaluatedLocally);

            expression = new FieldBinder().Bind(expression, elementType);
            expression = new QueryBinder(this, expression).Bind(expression);
            expression = new AggregateRewriter().Rewrite(expression);
            expression = new RedundantFieldRemover().Remove(expression);
            expression = new RedundantSubqueryRemover().Remove(expression);

            expression = new OrderByRewriter().Rewrite(expression);
            expression = new RedundantFieldRemover().Remove(expression);
            expression = new RedundantSubqueryRemover().Remove(expression);

            return(expression);
        }
Beispiel #15
0
    internal static Expression Optimize(Expression binded, QueryBinder binder, AliasGenerator aliasGenerator, HeavyProfiler.Tracer?log)
    {
        var isPostgres = Schema.Current.Settings.IsPostgres;


        log.Switch("Aggregate");
        Expression rewriten = AggregateRewriter.Rewrite(binded);

        log.Switch("DupHistory");
        Expression dupHistory = DuplicateHistory.Rewrite(rewriten, aliasGenerator);

        log.Switch("EntityCompleter");
        Expression completed = EntityCompleter.Complete(dupHistory, binder);

        log.Switch("AliasReplacer");
        Expression replaced = AliasProjectionReplacer.Replace(completed, aliasGenerator);

        log.Switch("OrderBy");
        Expression orderRewrited = OrderByRewriter.Rewrite(replaced);

        log.Switch("OrderBy");
        Expression lazyCastRemoved = SqlCastLazyRemover.Remove(orderRewrited);

        log.Switch("Rebinder");
        Expression rebinded = QueryRebinder.Rebind(lazyCastRemoved);

        log.Switch("UnusedColumn");
        Expression columnCleaned = UnusedColumnRemover.Remove(rebinded);

        log.Switch("Redundant");
        Expression subqueryCleaned = RedundantSubqueryRemover.Remove(columnCleaned);

        log.Switch("Condition");
        Expression rewriteConditions = isPostgres ? ConditionsRewriterPostgres.Rewrite(subqueryCleaned) : ConditionsRewriter.Rewrite(subqueryCleaned);

        log.Switch("Scalar");
        Expression scalar = ScalarSubqueryRewriter.Rewrite(rewriteConditions);

        return(scalar);
    }
        public override Expression Translate(Expression expression)
        {
            // fix up any order-by's
            expression = OrderByRewriter.Rewrite(expression);

            expression = base.Translate(expression);

            // convert skip/take info into RowNumber pattern
            if (isPaged(expression))
            {
                //we have some clean up here
                //paging embeds a SELECT in the FROM expression
                //this needs to be reset to the table name
                //and Skip/Take need to be reset
                var projection = expression as ProjectionExpression;

                //pull the select
                SelectExpression outer = projection.Source;

                //take out the nested FROM
                var inner = outer.From as SelectExpression;

                //and stick it on the outer
                outer.From = inner.From;

                //the outer Skip is in place
                //reset the Take since we need both on the Select
                //for the formatter to work
                outer.Take = inner.Take;


                expression = new ProjectionExpression(outer, projection.Projector);
            }

            // fix up any order-by's we may have changed
            expression = OrderByRewriter.Rewrite(expression);

            return(expression);
        }