Exemplo n.º 1
0
        /// <summary>
        /// Provides language specific query translation.  Use this to apply language specific rewrites or
        /// to make assertions/validations about the query.
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        public virtual Expression Translate(Expression expression)
        {
            // remove redundant layers again before cross apply rewrite
            expression = UnusedColumnRemover.Remove(expression);
            expression = RedundantColumnRemover.Remove(expression);
            expression = RedundantSubqueryRemover.Remove(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);
            }

            return(expression);
        }
Exemplo n.º 2
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)
            {
                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);
            }
Exemplo n.º 4
0
        public virtual Expression Translate(Expression 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);
            }

            return(expression);
        }