private static bool ProcessOuterApplyOverProject( RuleProcessingContext context, System.Data.Entity.Core.Query.InternalTrees.Node applyNode, out System.Data.Entity.Core.Query.InternalTrees.Node newNode) { newNode = applyNode; System.Data.Entity.Core.Query.InternalTrees.Node child1_1 = applyNode.Child1; System.Data.Entity.Core.Query.InternalTrees.Node child1_2 = child1_1.Child1; TransformationRulesContext transformationRulesContext = (TransformationRulesContext)context; Var computedVar = context.Command.GetExtendedNodeInfo(child1_1.Child0).NonNullableDefinitions.First; if (computedVar == null && child1_2.Children.Count == 1 && (child1_2.Child0.Child0.Op.OpType == OpType.InternalConstant || child1_2.Child0.Child0.Op.OpType == OpType.NullSentinel)) { return(false); } Command command = context.Command; System.Data.Entity.Core.Query.InternalTrees.Node node1 = (System.Data.Entity.Core.Query.InternalTrees.Node)null; InternalConstantOp internalConstantOp = (InternalConstantOp)null; ExtendedNodeInfo extendedNodeInfo1 = command.GetExtendedNodeInfo(child1_1.Child0); bool flag = false; foreach (System.Data.Entity.Core.Query.InternalTrees.Node child in child1_2.Children) { System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(child.Op.OpType == OpType.VarDef, "Expected VarDefOp. Found " + (object)child.Op.OpType + " instead"); VarRefOp op = child.Child0.Op as VarRefOp; if (op == null || !extendedNodeInfo1.Definitions.IsSet(op.Var)) { if (computedVar == null) { internalConstantOp = command.CreateInternalConstantOp(command.IntegerType, (object)1); System.Data.Entity.Core.Query.InternalTrees.Node node2 = command.CreateNode((Op)internalConstantOp); System.Data.Entity.Core.Query.InternalTrees.Node varDefListNode = command.CreateVarDefListNode(node2, out computedVar); ProjectOp projectOp = command.CreateProjectOp(computedVar); projectOp.Outputs.Or(extendedNodeInfo1.Definitions); node1 = command.CreateNode((Op)projectOp, child1_1.Child0, varDefListNode); } System.Data.Entity.Core.Query.InternalTrees.Node node3 = internalConstantOp == null || !internalConstantOp.IsEquivalent(child.Child0.Op) && child.Child0.Op.OpType != OpType.NullSentinel ? transformationRulesContext.BuildNullIfExpression(computedVar, child.Child0) : command.CreateNode((Op)command.CreateVarRefOp(computedVar)); child.Child0 = node3; command.RecomputeNodeInfo(child); flag = true; } } if (flag) { command.RecomputeNodeInfo(child1_2); } applyNode.Child1 = node1 ?? child1_1.Child0; command.RecomputeNodeInfo(applyNode); child1_1.Child0 = applyNode; ExtendedNodeInfo extendedNodeInfo2 = command.GetExtendedNodeInfo(applyNode.Child0); ((ProjectOp)child1_1.Op).Outputs.Or(extendedNodeInfo2.Definitions); newNode = child1_1; return(true); }
private static bool ProcessOuterApplyOverDummyProjectOverFilter( RuleProcessingContext context, System.Data.Entity.Core.Query.InternalTrees.Node applyNode, out System.Data.Entity.Core.Query.InternalTrees.Node newNode) { newNode = applyNode; System.Data.Entity.Core.Query.InternalTrees.Node child1 = applyNode.Child1; ProjectOp op = (ProjectOp)child1.Op; System.Data.Entity.Core.Query.InternalTrees.Node child0_1 = child1.Child0; System.Data.Entity.Core.Query.InternalTrees.Node child0_2 = child0_1.Child0; Command command = context.Command; ExtendedNodeInfo extendedNodeInfo1 = command.GetExtendedNodeInfo(child0_2); ExtendedNodeInfo extendedNodeInfo2 = command.GetExtendedNodeInfo(applyNode.Child0); if (op.Outputs.Overlaps(extendedNodeInfo2.Definitions) || extendedNodeInfo1.ExternalReferences.Overlaps(extendedNodeInfo2.Definitions)) { return(false); } bool flag1 = false; TransformationRulesContext transformationRulesContext = (TransformationRulesContext)context; Var int32Var; bool flag2; if (TransformationRulesContext.TryGetInt32Var((IEnumerable <Var>)extendedNodeInfo1.NonNullableDefinitions, out int32Var)) { flag2 = true; } else { int32Var = extendedNodeInfo1.NonNullableDefinitions.First; flag2 = false; } System.Data.Entity.Core.Query.InternalTrees.Node node1; if (int32Var != null) { flag1 = true; System.Data.Entity.Core.Query.InternalTrees.Node child0_3 = child1.Child1.Child0; child0_3.Child0 = child0_3.Child0.Op.OpType != OpType.NullSentinel || !flag2 || !transformationRulesContext.CanChangeNullSentinelValue ? transformationRulesContext.BuildNullIfExpression(int32Var, child0_3.Child0) : context.Command.CreateNode((Op)context.Command.CreateVarRefOp(int32Var)); command.RecomputeNodeInfo(child0_3); command.RecomputeNodeInfo(child1.Child1); node1 = child0_2; } else { node1 = child1; foreach (Var externalReference in command.GetNodeInfo(child0_1.Child1).ExternalReferences) { if (extendedNodeInfo1.Definitions.IsSet(externalReference)) { op.Outputs.Set(externalReference); } } child1.Child0 = child0_2; } context.Command.RecomputeNodeInfo(child1); System.Data.Entity.Core.Query.InternalTrees.Node node2 = command.CreateNode((Op)command.CreateLeftOuterJoinOp(), applyNode.Child0, node1, child0_1.Child1); if (flag1) { ExtendedNodeInfo extendedNodeInfo3 = command.GetExtendedNodeInfo(node2); child1.Child0 = node2; op.Outputs.Or(extendedNodeInfo3.Definitions); newNode = child1; } else { newNode = node2; } return(true); }