예제 #1
0
        internal Dictionary <Var, System.Data.Entity.Core.Query.InternalTrees.Node> GetVarMap(
            System.Data.Entity.Core.Query.InternalTrees.Node varDefListNode,
            Dictionary <Var, int> varRefMap)
        {
            VarDefListOp op1 = (VarDefListOp)varDefListNode.Op;
            Dictionary <Var, System.Data.Entity.Core.Query.InternalTrees.Node> dictionary = new Dictionary <Var, System.Data.Entity.Core.Query.InternalTrees.Node>();

            foreach (System.Data.Entity.Core.Query.InternalTrees.Node child in varDefListNode.Children)
            {
                VarDefOp op2 = (VarDefOp)child.Op;
                int      nonLeafNodeCount = 0;
                int      num = 0;
                if (!this.IsScalarOpTree(child.Child0, (Dictionary <Var, int>)null, ref nonLeafNodeCount) || nonLeafNodeCount > 100 && varRefMap != null && (varRefMap.TryGetValue(op2.Var, out num) && num > 2))
                {
                    return((Dictionary <Var, System.Data.Entity.Core.Query.InternalTrees.Node>)null);
                }
                System.Data.Entity.Core.Query.InternalTrees.Node node;
                if (dictionary.TryGetValue(op2.Var, out node))
                {
                    System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(node == child.Child0, "reusing varDef for different Node?");
                }
                else
                {
                    dictionary.Add(op2.Var, child.Child0);
                }
            }
            return(dictionary);
        }
예제 #2
0
        public override System.Data.Entity.Core.Query.InternalTrees.Node Visit(
            VarDefListOp op,
            System.Data.Entity.Core.Query.InternalTrees.Node n)
        {
            List <System.Data.Entity.Core.Query.InternalTrees.Node> args = new List <System.Data.Entity.Core.Query.InternalTrees.Node>();

            foreach (System.Data.Entity.Core.Query.InternalTrees.Node child in n.Children)
            {
                if (this.IsReferenced((child.Op as VarDefOp).Var))
                {
                    args.Add(this.VisitNode(child));
                }
            }
            return(this.m_command.CreateNode((Op)op, args));
        }
예제 #3
0
        private static bool ProcessGroupByOpWithNoAggregates(
            RuleProcessingContext context,
            System.Data.Entity.Core.Query.InternalTrees.Node n,
            out System.Data.Entity.Core.Query.InternalTrees.Node newNode)
        {
            Command          command          = context.Command;
            GroupByOp        op               = (GroupByOp)n.Op;
            ExtendedNodeInfo extendedNodeInfo = command.GetExtendedNodeInfo(n.Child0);
            ProjectOp        projectOp        = command.CreateProjectOp(op.Keys);
            VarDefListOp     varDefListOp     = command.CreateVarDefListOp();

            command.CreateNode((Op)varDefListOp);
            newNode = command.CreateNode((Op)projectOp, n.Child0, n.Child1);
            if (extendedNodeInfo.Keys.NoKeys || !op.Keys.Subsumes(extendedNodeInfo.Keys.KeyVars))
            {
                newNode = command.CreateNode((Op)command.CreateDistinctOp(command.CreateVarVec(op.Keys)), newNode);
            }
            return(true);
        }
예제 #4
0
        private static bool ProcessDistinctOpOfKeys(
            RuleProcessingContext context,
            Node n,
            out Node newNode)
        {
            Command          command          = context.Command;
            ExtendedNodeInfo extendedNodeInfo = command.GetExtendedNodeInfo(n.Child0);
            DistinctOp       op = (DistinctOp)n.Op;

            if (!extendedNodeInfo.Keys.NoKeys && op.Keys.Subsumes(extendedNodeInfo.Keys.KeyVars))
            {
                ProjectOp    projectOp    = command.CreateProjectOp(op.Keys);
                VarDefListOp varDefListOp = command.CreateVarDefListOp();
                Node         node         = command.CreateNode((Op)varDefListOp);
                newNode = command.CreateNode((Op)projectOp, n.Child0, node);
                return(true);
            }
            newNode = n;
            return(false);
        }
예제 #5
0
        // <summary>
        // VarDefListOp
        // Walks the children (VarDefOp), and looks for those whose Vars
        // have been referenced. Only those VarDefOps are visited - the
        // others are ignored.
        // At the end, a new list of children is created - with only those
        // VarDefOps that have been referenced
        // </summary>
        // <param name="op"> the varDefListOp </param>
        // <param name="n"> corresponding node </param>
        // <returns> modified node </returns>
        public override Node Visit(VarDefListOp op, Node n)
        {
            // NOTE: It would be nice to optimize this to only create a new node 
            //       and new list, if we needed to eliminate some arguments, but
            //       I'm not sure that the effort to eliminate the allocations 
            //       wouldn't be more expensive than the allocations themselves.
            //       It's something that we can consider if it shows up on the
            //       perf radar.

            // Get rid of all the children that we don't care about (ie)
            // those VarDefOp's that haven't been referenced
            var newChildren = new List<Node>();
            foreach (var chi in n.Children)
            {
                var varDefOp = chi.Op as VarDefOp;
                if (IsReferenced(varDefOp.Var))
                {
                    newChildren.Add(VisitNode(chi));
                }
            }
            return m_command.CreateNode(op, newChildren);
        }
예제 #6
0
 /// <summary>
 /// VarDefListOp handling
 /// </summary>
 /// <param name="op"></param>
 /// <param name="n"></param>
 public override void Visit(VarDefListOp op, Node n)
 {
     // Simply visit the children without pushing down any references to them.
     VisitChildren(n);
 }
        public override Node Visit(VarDefListOp op, Node n)
        {
            VisitChildren(n);

            var newChildren = new List<Node>();

            foreach (var chi in n.Children)
            {
                PlanCompiler.Assert(chi.Op is VarDefOp, "VarDefOp expected");

                var varDefOp = (VarDefOp)chi.Op;

                if (TypeUtils.IsStructuredType(varDefOp.Var.Type)
                    || TypeUtils.IsCollectionType(varDefOp.Var.Type))
                {
                    List<Node> newChiList;
                    md.TypeUsage x;

                    FlattenComputedVar((ComputedVar)varDefOp.Var, chi, out newChiList, out x);

                    foreach (var newChi in newChiList)
                    {
                        newChildren.Add(newChi);
                    }
                }
                else if (md.TypeSemantics.IsEnumerationType(varDefOp.Var.Type)
                         || md.TypeSemantics.IsStrongSpatialType(varDefOp.Var.Type))
                {
                    newChildren.Add(FlattenEnumOrStrongSpatialVar(varDefOp, chi.Child0));
                }
                else
                {
                    newChildren.Add(chi);
                }
            }
            var newVarDefListNode = m_command.CreateNode(n.Op, newChildren);
            return newVarDefListNode;
        }
예제 #8
0
 public override void Visit(VarDefListOp op, Node n)
 {
     VisitDefault(n);
     foreach (var chi in n.Children)
     {
         AssertOpType(chi.Op, OpType.VarDef);
     }
 }
 /// <summary>
 ///     Visitor pattern method for VarDefListOp
 /// </summary>
 /// <param name="op"> The VarDefListOp being visited </param>
 /// <param name="n"> The Node that references the Op </param>
 public virtual void Visit(VarDefListOp op, Node n)
 {
     VisitAncillaryOpDefault(op, n);
 }
 /// <summary>
 ///     VarDefListOp handling
 /// </summary>
 /// <param name="op"> </param>
 /// <param name="n"> </param>
 public override void Visit(VarDefListOp op, Node n)
 {
     // Simply visit the children without pushing down any references to them.
     VisitChildren(n);
 }
예제 #11
0
 // <summary>
 // Copies a VarDefListOp
 // </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(VarDefListOp op, Node n)
 {
     return CopyDefault(m_destCmd.CreateVarDefListOp(), n);
 }
예제 #12
0
 public override void Visit(VarDefListOp op, System.Data.Entity.Core.Query.InternalTrees.Node n)
 {
     this.VisitChildren(n);
 }