Example #1
0
            internal override SqlSource VisitJoin(SqlJoin join)
            {
                base.VisitJoin(join);
                switch (join.JoinType)
                {
                case SqlJoinType.Cross:
                case SqlJoinType.Inner:
                    return(join);

                case SqlJoinType.LeftOuter:
                case SqlJoinType.CrossApply:
                case SqlJoinType.OuterApply:
                {
                    if (!this.HasEmptySource(join.Right))
                    {
                        return(join);
                    }
                    SqlAlias right = (SqlAlias)join.Right;
                    this.removedMap[right] = right;
                    return(join.Left);
                }
                }
                return(join);
            }
Example #2
0
            internal override SqlSource VisitSource(SqlSource source)
            {
                source = base.VisitSource(source);
                SqlJoin node = source as SqlJoin;

                if (node != null)
                {
                    if (node.JoinType == SqlJoinType.OuterApply)
                    {
                        Dictionary <SqlAlias, bool>      aliasesForLifting = SqlGatherProducedAliases.Gather(node.Left);
                        Dictionary <SqlExpression, bool> liftedExpressions = new Dictionary <SqlExpression, bool>();
                        if (
                            (SqlOuterApplyReducer.SqlPredicateLifter.CanLift(node.Right, aliasesForLifting,
                                                                             liftedExpressions) &&
                             SqlOuterApplyReducer.SqlSelectionLifter.CanLift(node.Right, aliasesForLifting,
                                                                             liftedExpressions)) &&
                            !SqlOuterApplyReducer.SqlAliasDependencyChecker.IsDependent(node.Right, aliasesForLifting,
                                                                                        liftedExpressions))
                        {
                            SqlExpression expression = SqlOuterApplyReducer.SqlPredicateLifter.Lift(node.Right,
                                                                                                    aliasesForLifting);
                            List <List <SqlColumn> > list = SqlOuterApplyReducer.SqlSelectionLifter.Lift(node.Right,
                                                                                                         aliasesForLifting,
                                                                                                         liftedExpressions);
                            node.JoinType  = SqlJoinType.LeftOuter;
                            node.Condition = expression;
                            if (list != null)
                            {
                                foreach (List <SqlColumn> list2 in list)
                                {
                                    source = this.PushSourceDown(source, list2);
                                }
                            }
                        }
                        else
                        {
                            this.AnnotateSqlIncompatibility(node,
                                                            new SqlProvider.ProviderMode[]
                                                            { SqlProvider.ProviderMode.Sql2000 });
                        }
                    }
                    else if (node.JoinType == SqlJoinType.CrossApply)
                    {
                        SqlJoin leftOuterWithUnreferencedSingletonOnLeft =
                            this.GetLeftOuterWithUnreferencedSingletonOnLeft(node.Right);
                        if (leftOuterWithUnreferencedSingletonOnLeft != null)
                        {
                            Dictionary <SqlAlias, bool>      dictionary3 = SqlGatherProducedAliases.Gather(node.Left);
                            Dictionary <SqlExpression, bool> dictionary4 = new Dictionary <SqlExpression, bool>();
                            if (
                                (SqlOuterApplyReducer.SqlPredicateLifter.CanLift(
                                     leftOuterWithUnreferencedSingletonOnLeft.Right, dictionary3, dictionary4) &&
                                 SqlOuterApplyReducer.SqlSelectionLifter.CanLift(
                                     leftOuterWithUnreferencedSingletonOnLeft.Right, dictionary3, dictionary4)) &&
                                !SqlOuterApplyReducer.SqlAliasDependencyChecker.IsDependent(
                                    leftOuterWithUnreferencedSingletonOnLeft.Right, dictionary3, dictionary4))
                            {
                                SqlExpression right =
                                    SqlOuterApplyReducer.SqlPredicateLifter.Lift(
                                        leftOuterWithUnreferencedSingletonOnLeft.Right, dictionary3);
                                List <List <SqlColumn> > selections =
                                    SqlOuterApplyReducer.SqlSelectionLifter.Lift(
                                        leftOuterWithUnreferencedSingletonOnLeft.Right, dictionary3, dictionary4);
                                this.GetSelectionsBeforeJoin(node.Right, selections);
                                foreach (
                                    List <SqlColumn> list4 in
                                    selections.Where <List <SqlColumn> >(
                                        delegate(List <SqlColumn> s) { return(s.Count > 0); }))
                                {
                                    source = this.PushSourceDown(source, list4);
                                }
                                node.JoinType  = SqlJoinType.LeftOuter;
                                node.Condition =
                                    this.factory.AndAccumulate(leftOuterWithUnreferencedSingletonOnLeft.Condition, right);
                                node.Right = leftOuterWithUnreferencedSingletonOnLeft.Right;
                            }
                            else
                            {
                                this.AnnotateSqlIncompatibility(node,
                                                                new SqlProvider.ProviderMode[]
                                                                { SqlProvider.ProviderMode.Sql2000 });
                            }
                        }
                    }
                    while (node.JoinType == SqlJoinType.LeftOuter)
                    {
                        SqlJoin join3 = this.GetLeftOuterWithUnreferencedSingletonOnLeft(node.Left);
                        if (join3 == null)
                        {
                            return(source);
                        }
                        List <List <SqlColumn> > list5 = new List <List <SqlColumn> >();
                        this.GetSelectionsBeforeJoin(node.Left, list5);
                        foreach (List <SqlColumn> list6 in list5)
                        {
                            source = this.PushSourceDown(source, list6);
                        }
                        SqlSource     source2   = node.Right;
                        SqlExpression condition = node.Condition;
                        node.Left       = join3.Left;
                        node.Right      = join3;
                        node.Condition  = join3.Condition;
                        join3.Left      = join3.Right;
                        join3.Right     = source2;
                        join3.Condition = condition;
                    }
                }
                return(source);
            }
Example #3
0
 internal override SqlSource VisitJoin(SqlJoin join)
 {
     this.ReferenceColumns(join.Condition);
     return(base.VisitJoin(join));
 }