private static bool ProcessLogOpOverConstant( RuleProcessingContext context, System.Data.Entity.Core.Query.InternalTrees.Node node, System.Data.Entity.Core.Query.InternalTrees.Node constantPredicateNode, System.Data.Entity.Core.Query.InternalTrees.Node otherNode, out System.Data.Entity.Core.Query.InternalTrees.Node newNode) { System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(constantPredicateNode != null, "null constantPredicateOp?"); ConstantPredicateOp op = (ConstantPredicateOp)constantPredicateNode.Op; switch (node.Op.OpType) { case OpType.And: newNode = op.IsTrue ? otherNode : constantPredicateNode; break; case OpType.Or: newNode = op.IsTrue ? constantPredicateNode : otherNode; break; case OpType.Not: System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(otherNode == null, "Not Op with more than 1 child. Gasp!"); newNode = context.Command.CreateNode((Op)context.Command.CreateConstantPredicateOp(!op.Value)); break; default: System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(false, "Unexpected OpType - " + (object)node.Op.OpType); newNode = (System.Data.Entity.Core.Query.InternalTrees.Node)null; break; } return(true); }
/// <summary> /// Creates a new command /// </summary> internal Command(MetadataWorkspace metadataWorkspace) { m_parameterMap = new Dictionary<string, ParameterVar>(); m_vars = new List<Var>(); m_tables = new List<Table>(); m_metadataWorkspace = metadataWorkspace; if(!TryGetPrimitiveType(PrimitiveTypeKind.Boolean, out m_boolType)) { throw EntityUtil.ProviderIncompatible(System.Data.Entity.Strings.Cqt_General_NoProviderBooleanType); } if (!TryGetPrimitiveType(PrimitiveTypeKind.Int32, out m_intType)) { throw EntityUtil.ProviderIncompatible(System.Data.Entity.Strings.Cqt_General_NoProviderIntegerType); } if (!TryGetPrimitiveType(PrimitiveTypeKind.String, out m_stringType)) { throw EntityUtil.ProviderIncompatible(System.Data.Entity.Strings.Cqt_General_NoProviderStringType); } m_trueOp = new ConstantPredicateOp(m_boolType, true); m_falseOp = new ConstantPredicateOp(m_boolType, false); m_nodeInfoVisitor = new NodeInfoVisitor(this); m_keyPullupVisitor = new PlanCompiler.KeyPullup(this); // FreeLists m_freeVarVecEnumerators = new Stack<VarVec.VarVecEnumerator>(); m_freeVarVecs = new Stack<VarVec>(); m_referencedRelProperties = new HashSet<RelProperty>(); }
private static bool ProcessComparisonsOverConstant( RuleProcessingContext context, System.Data.Entity.Core.Query.InternalTrees.Node node, out System.Data.Entity.Core.Query.InternalTrees.Node newNode) { newNode = node; System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(node.Op.OpType == OpType.EQ || node.Op.OpType == OpType.NE, "unexpected comparison op type?"); bool?nullable = new bool?(node.Child0.Op.IsEquivalent(node.Child1.Op)); if (!nullable.HasValue) { return(false); } bool flag = node.Op.OpType == OpType.EQ ? nullable.Value : !nullable.Value; ConstantPredicateOp constantPredicateOp = context.Command.CreateConstantPredicateOp(flag); newNode = context.Command.CreateNode((Op)constantPredicateOp); return(true); }
private static bool ProcessApplyOverAnything( 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 child0 = applyNode.Child0; System.Data.Entity.Core.Query.InternalTrees.Node child1 = applyNode.Child1; ApplyBaseOp applyBaseOp = (ApplyBaseOp)applyNode.Op; Command command = context.Command; ExtendedNodeInfo extendedNodeInfo1 = command.GetExtendedNodeInfo(child1); ExtendedNodeInfo extendedNodeInfo2 = command.GetExtendedNodeInfo(child0); bool flag = false; if (applyBaseOp.OpType == OpType.OuterApply && extendedNodeInfo1.MinRows >= RowCount.One) { applyBaseOp = (ApplyBaseOp)command.CreateCrossApplyOp(); flag = true; } if (extendedNodeInfo1.ExternalReferences.Overlaps(extendedNodeInfo2.Definitions)) { if (!flag) { return(false); } newNode = command.CreateNode((Op)applyBaseOp, child0, child1); return(true); } if (applyBaseOp.OpType == OpType.CrossApply) { newNode = command.CreateNode((Op)command.CreateCrossJoinOp(), child0, child1); } else { LeftOuterJoinOp leftOuterJoinOp = command.CreateLeftOuterJoinOp(); ConstantPredicateOp trueOp = command.CreateTrueOp(); System.Data.Entity.Core.Query.InternalTrees.Node node = command.CreateNode((Op)trueOp); newNode = command.CreateNode((Op)leftOuterJoinOp, child0, child1, node); } return(true); }
private static bool ProcessLikeOverConstant( RuleProcessingContext context, System.Data.Entity.Core.Query.InternalTrees.Node n, out System.Data.Entity.Core.Query.InternalTrees.Node newNode) { newNode = n; InternalConstantOp op1 = (InternalConstantOp)n.Child1.Op; InternalConstantOp op2 = (InternalConstantOp)n.Child0.Op; string str1 = (string)op2.Value; string str2 = (string)op1.Value; bool?nullable = ScalarOpRules.MatchesPattern((string)op2.Value, (string)op1.Value); if (!nullable.HasValue) { return(false); } ConstantPredicateOp constantPredicateOp = context.Command.CreateConstantPredicateOp(nullable.Value); newNode = context.Command.CreateNode((Op)constantPredicateOp); return(true); }
/// <summary> /// Copies a ConstantPredicateOp /// </summary> /// <param name="op">The Op to Copy</param> /// <param name="n">The Node that references the Op</param> /// <returns>A copy of the original Node that references a copy of the original Op</returns> public override Node Visit(ConstantPredicateOp op, Node n) { return(m_destCmd.CreateNode(m_destCmd.CreateConstantPredicateOp(op.Value))); }
/// <summary> /// Visitor pattern method for ConstantPredicateOp /// </summary> /// <param name="op"> The ConstantPredicateOp being visited </param> /// <param name="n"> The Node that references the Op </param> public virtual void Visit(ConstantPredicateOp op, Node n) { VisitConstantOp(op, n); }
// <summary> // Copies a ConstantPredicateOp // </summary> // <param name="op"> The Op to Copy </param> // <param name="n"> The Node that references the Op </param> // <returns> A copy of the original Node that references a copy of the original Op </returns> public override Node Visit(ConstantPredicateOp op, Node n) { return m_destCmd.CreateNode(m_destCmd.CreateConstantPredicateOp(op.Value)); }
private static bool ProcessSimplifyCase_EliminateWhenClauses( RuleProcessingContext context, CaseOp caseOp, System.Data.Entity.Core.Query.InternalTrees.Node caseOpNode, out System.Data.Entity.Core.Query.InternalTrees.Node newNode) { List <System.Data.Entity.Core.Query.InternalTrees.Node> args = (List <System.Data.Entity.Core.Query.InternalTrees.Node>)null; newNode = caseOpNode; int index1 = 0; while (index1 < caseOpNode.Children.Count) { if (index1 == caseOpNode.Children.Count - 1) { if (OpType.SoftCast == caseOpNode.Children[index1].Op.OpType) { return(false); } if (args != null) { args.Add(caseOpNode.Children[index1]); break; } break; } if (OpType.SoftCast == caseOpNode.Children[index1 + 1].Op.OpType) { return(false); } if (caseOpNode.Children[index1].Op.OpType != OpType.ConstantPredicate) { if (args != null) { args.Add(caseOpNode.Children[index1]); args.Add(caseOpNode.Children[index1 + 1]); } index1 += 2; } else { ConstantPredicateOp op = (ConstantPredicateOp)caseOpNode.Children[index1].Op; if (args == null) { args = new List <System.Data.Entity.Core.Query.InternalTrees.Node>(); for (int index2 = 0; index2 < index1; ++index2) { args.Add(caseOpNode.Children[index2]); } } if (op.IsTrue) { args.Add(caseOpNode.Children[index1 + 1]); break; } System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(op.IsFalse, "constant predicate must be either true or false"); index1 += 2; } } if (args == null) { return(false); } System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(args.Count > 0, "new args list must not be empty"); newNode = args.Count != 1 ? context.Command.CreateNode((Op)caseOp, args) : args[0]; return(true); }