Example #1
0
 private Node Or(Node x, Node y)
 {
     return(_command.CreateNode(
                _command.CreateConditionalOp(OpType.Or),
                OpCopier.Copy(_command, x),
                OpCopier.Copy(_command, y)));
 }
Example #2
0
 internal System.Data.Entity.Core.Query.InternalTrees.Node Copy(System.Data.Entity.Core.Query.InternalTrees.Node node)
 {
     if (node.Op.OpType == OpType.VarRef)
     {
         return(this.Command.CreateNode((Op)this.Command.CreateVarRefOp((node.Op as VarRefOp).Var)));
     }
     return(OpCopier.Copy(this.Command, node));
 }
Example #3
0
 public override System.Data.Entity.Core.Query.InternalTrees.Node Visit(
     VarRefOp op,
     System.Data.Entity.Core.Query.InternalTrees.Node n)
 {
     System.Data.Entity.Core.Query.InternalTrees.Node n1;
     if (op.Var.VarType == VarType.Parameter && this.m_viewArguments.TryGetValue(((ParameterVar)op.Var).ParameterName, out n1))
     {
         return(OpCopier.Copy(this.m_destCmd, n1));
     }
     return(base.Visit(op, n));
 }
Example #4
0
 internal System.Data.Entity.Core.Query.InternalTrees.Node GetInternalTree(
     Command targetIqtCommand)
 {
     if (this.m_internalTreeNode == null)
     {
         Command command = ITreeGenerator.Generate(this.GetCommandTree(), this.m_discriminatorMap);
         System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(command.Root.Op.OpType == OpType.PhysicalProject, "Expected a physical projectOp at the root of the tree - found " + (object)command.Root.Op.OpType);
         command.DisableVarVecEnumCaching();
         this.m_internalTreeNode = command.Root.Child0;
     }
     return(OpCopier.Copy(targetIqtCommand, this.m_internalTreeNode));
 }
 // <summary>
 // Makes a copy of the appropriate subtree - with a simple accelerator for VarRefOp
 // since that's likely to be the most command case
 // </summary>
 // <param name="node"> the subtree to copy </param>
 // <returns> the copy of the subtree </returns>
 internal Node Copy(Node node)
 {
     if (node.Op.OpType
         == OpType.VarRef)
     {
         var op = node.Op as VarRefOp;
         return(Command.CreateNode(Command.CreateVarRefOp(op.Var)));
     }
     else
     {
         return(OpCopier.Copy(Command, node));
     }
 }
Example #6
0
 internal Node GetInternalTree(Command targetIqtCommand)
 {
     Debug.Assert(m_extent.EntityContainer.DataSpace == DataSpace.CSpace, "Internal Tree should be asked only for query view");
     if (m_internalTreeNode == null)
     {
         DbQueryCommandTree tree = GetCommandTree();
         // Convert this into an ITree first
         Command itree = ITreeGenerator.Generate(tree, m_discriminatorMap);
         // Pull out the root physical project-op, and copy this itree into our own itree
         PlanCompiler.Assert(itree.Root.Op.OpType == OpType.PhysicalProject,
                             "Expected a physical projectOp at the root of the tree - found " + itree.Root.Op.OpType);
         // #554756: VarVec enumerators are not cached on the shared Command instance.
         itree.DisableVarVecEnumCaching();
         m_internalTreeNode = itree.Root.Child0;
     }
     Debug.Assert(m_internalTreeNode != null, "m_internalTreeNode != null");
     return(OpCopier.Copy(targetIqtCommand, m_internalTreeNode));
 }
        private void TryProcessCandidate(
            KeyValuePair <System.Data.Entity.Core.Query.InternalTrees.Node, System.Data.Entity.Core.Query.InternalTrees.Node> candidate,
            GroupAggregateVarInfo groupAggregateVarInfo)
        {
            System.Data.Entity.Core.Query.InternalTrees.Node         definingGroupNode = groupAggregateVarInfo.DefiningGroupNode;
            IList <System.Data.Entity.Core.Query.InternalTrees.Node> ancestors1;
            IList <System.Data.Entity.Core.Query.InternalTrees.Node> ancestors2;

            this.FindPathsToLeastCommonAncestor(candidate.Key, definingGroupNode, out ancestors1, out ancestors2);
            if (!AggregatePushdown.AreAllNodesSupportedForPropagation(ancestors2))
            {
                return;
            }
            GroupByIntoOp op1 = (GroupByIntoOp)definingGroupNode.Op;

            System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(op1.Inputs.Count == 1, "There should be one input var to GroupByInto at this stage");
            Var        first = op1.Inputs.First;
            FunctionOp op2   = (FunctionOp)candidate.Key.Op;

            System.Data.Entity.Core.Query.InternalTrees.Node subTree = OpCopier.Copy(this.m_command, candidate.Value);
            new VarRemapper(this.m_command, new Dictionary <Var, Var>(1)
            {
                {
                    groupAggregateVarInfo.GroupAggregateVar,
                    first
                }
            }).RemapSubtree(subTree);
            Var computedVar;

            System.Data.Entity.Core.Query.InternalTrees.Node varDefNode = this.m_command.CreateVarDefNode(this.m_command.CreateNode((Op)this.m_command.CreateAggregateOp(op2.Function, false), subTree), out computedVar);
            definingGroupNode.Child2.Children.Add(varDefNode);
            ((GroupByBaseOp)definingGroupNode.Op).Outputs.Set(computedVar);
            for (int index = 0; index < ancestors2.Count; ++index)
            {
                System.Data.Entity.Core.Query.InternalTrees.Node node = ancestors2[index];
                if (node.Op.OpType == OpType.Project)
                {
                    ((ProjectOp)node.Op).Outputs.Set(computedVar);
                }
            }
            candidate.Key.Op = (Op)this.m_command.CreateVarRefOp(computedVar);
            candidate.Key.Children.Clear();
        }
Example #8
0
            public override Node Visit(VarRefOp op, Node n)
            {
                // The original function view has store function calls with arguments represented as command parameter refs.
                // We are now replacing command parameter refs with the real argument nodes from the calling tree.
                // The replacement is performed in the function view subtree and we search for parameter refs with names
                // matching the FunctionImportMapping.FunctionImport parameter names (this is how the command parameters
                // have been created in the first place, see m_commandParameters and GetCommandTree(...) for more info).
                // The search and replace is not performed on the argument nodes themselves. This is important because it guarantees
                // that we are not replacing unrelated (possibly user-defined) parameter refs that accidentally have the matching names.
                Node argNode;

                if (op.Var.VarType == VarType.Parameter && m_viewArguments.TryGetValue(((ParameterVar)op.Var).ParameterName, out argNode))
                {
                    // Just copy the argNode, do not reapply this visitor. We do not want search and replace inside the argNode. See comment above.
                    return(OpCopier.Copy(m_destCmd, argNode));
                }
                else
                {
                    return(base.Visit(op, n));
                }
            }
        private void TryProcessCandidate(
            KeyValuePair <Node, Node> candidate,
            GroupAggregateVarInfo groupAggregateVarInfo)
        {
            IList <Node> functionAncestors;
            IList <Node> groupByAncestors;
            var          definingGroupNode = groupAggregateVarInfo.DefiningGroupNode;

            FindPathsToLeastCommonAncestor(candidate.Key, definingGroupNode, out functionAncestors, out groupByAncestors);

            //Check whether all ancestors of the GroupByInto node are of type that we support propagating through
            if (!AreAllNodesSupportedForPropagation(groupByAncestors))
            {
                return;
            }

            //Add the function to the group by node
            var definingGroupOp = (GroupByIntoOp)definingGroupNode.Op;

            PlanCompiler.Assert(definingGroupOp.Inputs.Count == 1, "There should be one input var to GroupByInto at this stage");
            var inputVar   = definingGroupOp.Inputs.First;
            var functionOp = (FunctionOp)candidate.Key.Op;

            //
            // Remap the template from referencing the groupAggregate var to reference the input to
            // the group by into
            //
            var argumentNode = OpCopier.Copy(m_command, candidate.Value);
            var dictionary   = new Dictionary <Var, Var>(1);

            dictionary.Add(groupAggregateVarInfo.GroupAggregateVar, inputVar);
            var remapper = new VarRemapper(m_command, dictionary);

            remapper.RemapSubtree(argumentNode);

            var newFunctionDefiningNode = m_command.CreateNode(
                m_command.CreateAggregateOp(functionOp.Function, false),
                argumentNode);

            Var newFunctionVar;
            var varDefNode = m_command.CreateVarDefNode(newFunctionDefiningNode, out newFunctionVar);

            // Add the new aggregate to the list of aggregates
            definingGroupNode.Child2.Children.Add(varDefNode);
            var groupByOp = (GroupByIntoOp)definingGroupNode.Op;

            groupByOp.Outputs.Set(newFunctionVar);

            //Propagate the new var throught the ancestors of the GroupByInto
            for (var i = 0; i < groupByAncestors.Count; i++)
            {
                var groupByAncestor = groupByAncestors[i];
                if (groupByAncestor.Op.OpType
                    == OpType.Project)
                {
                    var ancestorProjectOp = (ProjectOp)groupByAncestor.Op;
                    ancestorProjectOp.Outputs.Set(newFunctionVar);
                }
            }

            //Update the functionNode
            candidate.Key.Op = m_command.CreateVarRefOp(newFunctionVar);
            candidate.Key.Children.Clear();
        }
Example #10
0
 private Node Clone(Node x)
 {
     return(OpCopier.Copy(this._command, x));
 }
Example #11
0
 private Node Not(Node x)
 {
     return(_command.CreateNode(
                _command.CreateConditionalOp(OpType.Not),
                OpCopier.Copy(_command, x)));
 }
Example #12
0
 private Node IsNull(Node x)
 {
     return(_command.CreateNode(
                _command.CreateConditionalOp(OpType.IsNull),
                OpCopier.Copy(_command, x)));
 }