Esempio n. 1
0
        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);
        }
Esempio n. 2
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);
    }