Beispiel #1
0
        public override AlgebraNode VisitHashMatchAlgebraNode(HashMatchAlgebraNode node)
        {
            ShowPlanElement buildElement = ConvertNode(node.Left);
            ShowPlanElement probeElement = ConvertNode(node.Right);

            PropertyListBuilder propertyListBuilder = new PropertyListBuilder();

            AddRowBufferEntries(propertyListBuilder, Resources.ShowPlanGroupOutputList, node.OutputList);
            AddStatistics(propertyListBuilder, node.StatisticsIterator);

            WriteRowBufferEntry(propertyListBuilder, Resources.ShowPlanKeyHashKeysBuild, node.BuildKeyEntry);
            WriteRowBufferEntry(propertyListBuilder, Resources.ShowPlanKeyHashKeysProbe, node.ProbeEntry);
            propertyListBuilder.Write(Resources.ShowPlanKeyLogicalOperator, LogicalOperatorToString(node.Op));

            if (node.ProbeResidual != null)
            {
                propertyListBuilder.Write(Resources.ShowPlanKeyProbeResidual, node.ProbeResidual.GenerateSource());
            }

            IList <ShowPlanProperty> properties = propertyListBuilder.ToList();

            ShowPlanElement element = new ShowPlanElement(ShowPlanOperator.HashMatch, properties, buildElement, probeElement);

            _currentElement = element;

            return(node);
        }
Beispiel #2
0
        public override AlgebraNode VisitHashMatchAlgebraNode(HashMatchAlgebraNode node)
        {
            node.Left = VisitAlgebraNode(node.Left);
            node.Right = VisitAlgebraNode(node.Right);

            List<RowBufferEntry> outputList = new List<RowBufferEntry>();
            outputList.AddRange(node.Left.OutputList);
            outputList.AddRange(node.Right.OutputList);
            node.OutputList = outputList.ToArray();

            return node;
        }
Beispiel #3
0
        public virtual AlgebraNode VisitHashMatchAlgebraNode(HashMatchAlgebraNode node)
        {
            node.Left  = VisitAlgebraNode(node.Left);
            node.Right = VisitAlgebraNode(node.Right);

            if (node.ProbeResidual != null)
            {
                node.ProbeResidual = VisitExpression(node.ProbeResidual);
            }

            return(node);
        }
Beispiel #4
0
        public override AlgebraNode VisitHashMatchAlgebraNode(HashMatchAlgebraNode node)
        {
            node.Left  = VisitAlgebraNode(node.Left);
            node.Right = VisitAlgebraNode(node.Right);

            List <RowBufferEntry> outputList = new List <RowBufferEntry>();

            outputList.AddRange(node.Left.OutputList);
            outputList.AddRange(node.Right.OutputList);
            node.OutputList = outputList.ToArray();

            return(node);
        }
Beispiel #5
0
		public override AstElement Clone(Dictionary<AstElement, AstElement> alreadyClonedElements)
		{
			HashMatchAlgebraNode result = new HashMatchAlgebraNode();
			result.StatisticsIterator = StatisticsIterator;
			result.OutputList = ArrayHelpers.Clone(OutputList);
			result.Left = (AlgebraNode)_left.Clone(alreadyClonedElements);
			result.Right = (AlgebraNode)_right.Clone(alreadyClonedElements);
			result.Op = _op;
			result.BuildKeyEntry = _buildKeyEntry;
			result.ProbeEntry = _probeEntry;
			result.ProbeResidual = (ExpressionNode)_probeResidual.Clone(alreadyClonedElements);
			return result;
		}
        public override AlgebraNode VisitHashMatchAlgebraNode(HashMatchAlgebraNode node)
        {
            node.OutputList = RemovedUnneededRowBufferColumns(node.OutputList);

            AddNeededRowBufferEntry(node.BuildKeyEntry);
            AddNeededRowBufferEntry(node.ProbeEntry);

            if (node.ProbeResidual != null)
            {
                AddNeededRowBufferEntryReferences(node.ProbeResidual);
            }

            return(base.VisitHashMatchAlgebraNode(node));
        }
Beispiel #7
0
        public override AstElement Clone(Dictionary <AstElement, AstElement> alreadyClonedElements)
        {
            HashMatchAlgebraNode result = new HashMatchAlgebraNode();

            result.StatisticsIterator = StatisticsIterator;
            result.OutputList         = ArrayHelpers.Clone(OutputList);
            result.Left          = (AlgebraNode)_left.Clone(alreadyClonedElements);
            result.Right         = (AlgebraNode)_right.Clone(alreadyClonedElements);
            result.Op            = _op;
            result.BuildKeyEntry = _buildKeyEntry;
            result.ProbeEntry    = _probeEntry;
            result.ProbeResidual = (ExpressionNode)_probeResidual.Clone(alreadyClonedElements);
            return(result);
        }
Beispiel #8
0
		public override AlgebraNode VisitHashMatchAlgebraNode(HashMatchAlgebraNode node)
		{
			HashMatchIterator hashMatchIterator = new HashMatchIterator();
			hashMatchIterator.RowBuffer = new object[node.OutputList.Length];
			hashMatchIterator.Left = ConvertAlgebraNode(node.Left);
			hashMatchIterator.LeftOutput = GetIteratorOutput(0, node.Left.OutputList, node.OutputList);
			hashMatchIterator.Right = ConvertAlgebraNode(node.Right);
			hashMatchIterator.RightOutput = GetIteratorOutput(hashMatchIterator.LeftOutput.Length, node.Right.OutputList, node.OutputList);
			hashMatchIterator.BuildKeyEntry = GetIteratorInput(node.Left.OutputList, new RowBufferEntry[] { node.BuildKeyEntry })[0];
			hashMatchIterator.ProbeEntry = GetIteratorInput(node.Right.OutputList, new RowBufferEntry[] { node.ProbeEntry })[0];

			switch (node.Op)
			{
				case JoinAlgebraNode.JoinOperator.InnerJoin:
					hashMatchIterator.LogicalOp = JoinType.Inner;
					break;
				case JoinAlgebraNode.JoinOperator.RightOuterJoin:
					hashMatchIterator.LogicalOp = JoinType.RightOuter;
					break;
				case JoinAlgebraNode.JoinOperator.FullOuterJoin:
					hashMatchIterator.LogicalOp = JoinType.FullOuter;
					break;
				default:
					throw ExceptionBuilder.UnhandledCaseLabel(node.Op);
			}

			UpdatePredicateRowBufferReferences(hashMatchIterator, node);
			SetLastIterator(node, hashMatchIterator);

			return node;
		}
Beispiel #9
0
		private void UpdatePredicateRowBufferReferences(HashMatchIterator hashMatchIterator, HashMatchAlgebraNode node)
		{
			if (node.ProbeResidual != null)
			{
				BoundRowBufferEntrySet leftBoundRowBufferEntrySet = new BoundRowBufferEntrySet(hashMatchIterator.Left.RowBuffer, node.Left.OutputList);
				BoundRowBufferEntrySet rightBoundRowBufferEntrySet = new BoundRowBufferEntrySet(hashMatchIterator.Right.RowBuffer, node.Right.OutputList);
				hashMatchIterator.ProbeResidual = CreateRuntimeExpression(node.ProbeResidual, leftBoundRowBufferEntrySet, rightBoundRowBufferEntrySet);
			}
		}
Beispiel #10
0
		public virtual AlgebraNode VisitHashMatchAlgebraNode(HashMatchAlgebraNode node)
		{
			node.Left = VisitAlgebraNode(node.Left);
			node.Right = VisitAlgebraNode(node.Right);

			if (node.ProbeResidual != null)
				node.ProbeResidual = VisitExpression(node.ProbeResidual);

			return node;
		}
        public override AlgebraNode VisitJoinAlgebraNode(JoinAlgebraNode node)
        {
            node.Left = VisitAlgebraNode(node.Left);
            node.Right = VisitAlgebraNode(node.Right);

            if (node.Predicate != null &&
                (node.OuterReferences == null || node.OuterReferences.Length == 0) &&
                (
                    node.Op == JoinAlgebraNode.JoinOperator.InnerJoin ||
                    node.Op == JoinAlgebraNode.JoinOperator.LeftOuterJoin ||
                    node.Op == JoinAlgebraNode.JoinOperator.RightOuterJoin ||
                    node.Op == JoinAlgebraNode.JoinOperator.FullOuterJoin)
                )
            {
                RowBufferEntry[] leftDefinedEntries = AstUtil.GetDefinedValueEntries(node.Left);
                RowBufferEntry[] rightDefinedEntries = AstUtil.GetDefinedValueEntries(node.Right);

                EqualPredicatesExtractor equalPredicatesExtractor = new EqualPredicatesExtractor(leftDefinedEntries, rightDefinedEntries);
                ExpressionNode probeResidual = equalPredicatesExtractor.VisitExpression(node.Predicate);
                BinaryExpression[] equalPredicates = equalPredicatesExtractor.GetEqualPredicates();

                if (equalPredicates.Length > 0)
                {
                    BinaryExpression equalPredicate = equalPredicates[0];

                    ExpressionBuilder expressionBuilder = new ExpressionBuilder();
                    expressionBuilder.Push(probeResidual);

                    if (equalPredicates.Length > 1)
                    {
                        for (int i = 1; i < equalPredicates.Length; i++)
                            expressionBuilder.Push(equalPredicates[i]);
                        expressionBuilder.PushNAry(LogicalOperator.And);
                    }

                    probeResidual = expressionBuilder.Pop();
                    if (probeResidual is ConstantExpression)
                        probeResidual = null;

                    AlgebraNode leftInput = node.Left;
                    AlgebraNode rightInput = node.Right;

                    if (node.Op == JoinAlgebraNode.JoinOperator.LeftOuterJoin)
                    {
                        node.Op = JoinAlgebraNode.JoinOperator.RightOuterJoin;
                        leftInput = node.Right;
                        rightInput = node.Left;
                        ExpressionNode oldLeft = equalPredicate.Left;
                        equalPredicate.Left = equalPredicate.Right;
                        equalPredicate.Right = oldLeft;
                    }

                    RowBufferEntry leftEntry;
                    RowBufferEntryExpression leftAsRowBufferEntryExpression = equalPredicate.Left as RowBufferEntryExpression;
                    if (leftAsRowBufferEntryExpression != null)
                    {
                        leftEntry = leftAsRowBufferEntryExpression.RowBufferEntry;
                    }
                    else
                    {
                        leftEntry = new RowBufferEntry(equalPredicate.Left.ExpressionType);
                        ComputedValueDefinition definedValue = new ComputedValueDefinition();
                        definedValue.Target = leftEntry;
                        definedValue.Expression = equalPredicate.Left;

                        ComputeScalarAlgebraNode computeScalarAlgebraNode = new ComputeScalarAlgebraNode();
                        computeScalarAlgebraNode.Input = leftInput;
                        computeScalarAlgebraNode.DefinedValues = new ComputedValueDefinition[] {definedValue};
                        leftInput = computeScalarAlgebraNode;
                    }

                    RowBufferEntry rightEntry;
                    RowBufferEntryExpression rightAsRowBufferEntryExpression = equalPredicate.Right as RowBufferEntryExpression;
                    if (rightAsRowBufferEntryExpression != null)
                    {
                        rightEntry = rightAsRowBufferEntryExpression.RowBufferEntry;
                    }
                    else
                    {
                        rightEntry = new RowBufferEntry(equalPredicate.Right.ExpressionType);
                        ComputedValueDefinition definedValue = new ComputedValueDefinition();
                        definedValue.Target = rightEntry;
                        definedValue.Expression = equalPredicate.Right;

                        ComputeScalarAlgebraNode computeScalarAlgebraNode = new ComputeScalarAlgebraNode();
                        computeScalarAlgebraNode.Input = rightInput;
                        computeScalarAlgebraNode.DefinedValues = new ComputedValueDefinition[] {definedValue};
                        rightInput = computeScalarAlgebraNode;
                    }

                    HashMatchAlgebraNode hashMatchAlgebraNode = new HashMatchAlgebraNode();
                    hashMatchAlgebraNode.Op = node.Op;
                    hashMatchAlgebraNode.Left = leftInput;
                    hashMatchAlgebraNode.Right = rightInput;
                    hashMatchAlgebraNode.BuildKeyEntry = leftEntry;
                    hashMatchAlgebraNode.ProbeEntry = rightEntry;
                    hashMatchAlgebraNode.ProbeResidual = probeResidual;
                    return hashMatchAlgebraNode;
                }
            }

            return node;
        }
Beispiel #12
0
        public override AlgebraNode VisitJoinAlgebraNode(JoinAlgebraNode node)
        {
            node.Left  = VisitAlgebraNode(node.Left);
            node.Right = VisitAlgebraNode(node.Right);

            if (node.Predicate != null &&
                (node.OuterReferences == null || node.OuterReferences.Length == 0) &&
                (
                    node.Op == JoinAlgebraNode.JoinOperator.InnerJoin ||
                    node.Op == JoinAlgebraNode.JoinOperator.LeftOuterJoin ||
                    node.Op == JoinAlgebraNode.JoinOperator.RightOuterJoin ||
                    node.Op == JoinAlgebraNode.JoinOperator.FullOuterJoin)
                )
            {
                RowBufferEntry[] leftDefinedEntries  = AstUtil.GetDefinedValueEntries(node.Left);
                RowBufferEntry[] rightDefinedEntries = AstUtil.GetDefinedValueEntries(node.Right);

                EqualPredicatesExtractor equalPredicatesExtractor = new EqualPredicatesExtractor(leftDefinedEntries, rightDefinedEntries);
                ExpressionNode           probeResidual            = equalPredicatesExtractor.VisitExpression(node.Predicate);
                BinaryExpression[]       equalPredicates          = equalPredicatesExtractor.GetEqualPredicates();

                if (equalPredicates.Length > 0)
                {
                    BinaryExpression equalPredicate = equalPredicates[0];

                    ExpressionBuilder expressionBuilder = new ExpressionBuilder();
                    expressionBuilder.Push(probeResidual);

                    if (equalPredicates.Length > 1)
                    {
                        for (int i = 1; i < equalPredicates.Length; i++)
                        {
                            expressionBuilder.Push(equalPredicates[i]);
                        }
                        expressionBuilder.PushNAry(LogicalOperator.And);
                    }

                    probeResidual = expressionBuilder.Pop();
                    if (probeResidual is ConstantExpression)
                    {
                        probeResidual = null;
                    }

                    AlgebraNode leftInput  = node.Left;
                    AlgebraNode rightInput = node.Right;

                    if (node.Op == JoinAlgebraNode.JoinOperator.LeftOuterJoin)
                    {
                        node.Op    = JoinAlgebraNode.JoinOperator.RightOuterJoin;
                        leftInput  = node.Right;
                        rightInput = node.Left;
                        ExpressionNode oldLeft = equalPredicate.Left;
                        equalPredicate.Left  = equalPredicate.Right;
                        equalPredicate.Right = oldLeft;
                    }

                    RowBufferEntry           leftEntry;
                    RowBufferEntryExpression leftAsRowBufferEntryExpression = equalPredicate.Left as RowBufferEntryExpression;
                    if (leftAsRowBufferEntryExpression != null)
                    {
                        leftEntry = leftAsRowBufferEntryExpression.RowBufferEntry;
                    }
                    else
                    {
                        leftEntry = new RowBufferEntry(equalPredicate.Left.ExpressionType);
                        ComputedValueDefinition definedValue = new ComputedValueDefinition();
                        definedValue.Target     = leftEntry;
                        definedValue.Expression = equalPredicate.Left;

                        ComputeScalarAlgebraNode computeScalarAlgebraNode = new ComputeScalarAlgebraNode();
                        computeScalarAlgebraNode.Input         = leftInput;
                        computeScalarAlgebraNode.DefinedValues = new ComputedValueDefinition[] { definedValue };
                        leftInput = computeScalarAlgebraNode;
                    }

                    RowBufferEntry           rightEntry;
                    RowBufferEntryExpression rightAsRowBufferEntryExpression = equalPredicate.Right as RowBufferEntryExpression;
                    if (rightAsRowBufferEntryExpression != null)
                    {
                        rightEntry = rightAsRowBufferEntryExpression.RowBufferEntry;
                    }
                    else
                    {
                        rightEntry = new RowBufferEntry(equalPredicate.Right.ExpressionType);
                        ComputedValueDefinition definedValue = new ComputedValueDefinition();
                        definedValue.Target     = rightEntry;
                        definedValue.Expression = equalPredicate.Right;

                        ComputeScalarAlgebraNode computeScalarAlgebraNode = new ComputeScalarAlgebraNode();
                        computeScalarAlgebraNode.Input         = rightInput;
                        computeScalarAlgebraNode.DefinedValues = new ComputedValueDefinition[] { definedValue };
                        rightInput = computeScalarAlgebraNode;
                    }

                    HashMatchAlgebraNode hashMatchAlgebraNode = new HashMatchAlgebraNode();
                    hashMatchAlgebraNode.Op            = node.Op;
                    hashMatchAlgebraNode.Left          = leftInput;
                    hashMatchAlgebraNode.Right         = rightInput;
                    hashMatchAlgebraNode.BuildKeyEntry = leftEntry;
                    hashMatchAlgebraNode.ProbeEntry    = rightEntry;
                    hashMatchAlgebraNode.ProbeResidual = probeResidual;
                    return(hashMatchAlgebraNode);
                }
            }

            return(node);
        }
Beispiel #13
0
        public override AlgebraNode VisitHashMatchAlgebraNode(HashMatchAlgebraNode node)
        {
            ShowPlanElement buildElement = ConvertNode(node.Left);
            ShowPlanElement probeElement = ConvertNode(node.Right);

            PropertyListBuilder propertyListBuilder = new PropertyListBuilder();
            AddRowBufferEntries(propertyListBuilder, Resources.ShowPlanGroupOutputList, node.OutputList);
            AddStatistics(propertyListBuilder, node.StatisticsIterator);

            WriteRowBufferEntry(propertyListBuilder, Resources.ShowPlanKeyHashKeysBuild, node.BuildKeyEntry);
            WriteRowBufferEntry(propertyListBuilder, Resources.ShowPlanKeyHashKeysProbe, node.ProbeEntry);
            propertyListBuilder.Write(Resources.ShowPlanKeyLogicalOperator, LogicalOperatorToString(node.Op));

            if (node.ProbeResidual != null)
                propertyListBuilder.Write(Resources.ShowPlanKeyProbeResidual, node.ProbeResidual.GenerateSource());

            IList<ShowPlanProperty> properties = propertyListBuilder.ToList();

            ShowPlanElement element = new ShowPlanElement(ShowPlanOperator.HashMatch, properties, buildElement, probeElement);
            _currentElement = element;

            return node;
        }