Esempio n. 1
0
        public override AlgebraNode VisitTableAlgebraNode(TableAlgebraNode node)
        {
            node.DefinedValues = RemovedUnneededDefinedValues(node.DefinedValues);
            node.OutputList    = GetRowBufferEntries(node.DefinedValues);

            return(base.VisitTableAlgebraNode(node));
        }
Esempio n. 2
0
		public override AstElement Clone(Dictionary<AstElement, AstElement> alreadyClonedElements)
		{
			TableAlgebraNode result = new TableAlgebraNode();
			result.StatisticsIterator = StatisticsIterator;
			result.OutputList = ArrayHelpers.Clone(OutputList);
			result.TableRefBinding = _tableRefBinding;
			result.DefinedValues = ArrayHelpers.CreateDeepCopyOfAstElementArray(_definedValues, alreadyClonedElements);
			return result;
		}
Esempio n. 3
0
        public override AlgebraNode VisitTableAlgebraNode(TableAlgebraNode node)
        {
            base.VisitTableAlgebraNode(node);

            foreach (ColumnValueDefinition definedValue in node.DefinedValues)
                _rowBufferEntries.Add(definedValue.Target);

            return node;
        }
Esempio n. 4
0
        public override AlgebraNode VisitTableAlgebraNode(TableAlgebraNode node)
        {
            _xmlWriter.WriteStartElement("tableAlgebraNode");
            WriteTableRef(node.TableRefBinding);

            _xmlWriter.WriteEndElement();

            return(node);
        }
Esempio n. 5
0
        public override AstElement Clone(Dictionary <AstElement, AstElement> alreadyClonedElements)
        {
            TableAlgebraNode result = new TableAlgebraNode();

            result.StatisticsIterator = StatisticsIterator;
            result.OutputList         = ArrayHelpers.Clone(OutputList);
            result.TableRefBinding    = _tableRefBinding;
            result.DefinedValues      = ArrayHelpers.CreateDeepCopyOfAstElementArray(_definedValues, alreadyClonedElements);
            return(result);
        }
Esempio n. 6
0
        public override AlgebraNode VisitTableAlgebraNode(TableAlgebraNode node)
        {
            base.VisitTableAlgebraNode(node);

            foreach (ColumnValueDefinition definedValue in node.DefinedValues)
            {
                _rowBufferEntries.Add(definedValue.Target);
            }

            return(node);
        }
Esempio n. 7
0
        public override TableReference VisitNamedTableReference(NamedTableReference node)
        {
            CommonTableBinding tableBindingAsCommonTable = node.TableRefBinding.TableBinding as CommonTableBinding;

            if (tableBindingAsCommonTable == null)
            {
                // It is a regular table reference. Emit just a table node.

                List <ColumnValueDefinition> definedValues = new List <ColumnValueDefinition>();
                foreach (ColumnRefBinding columnRefBinding in node.TableRefBinding.ColumnRefs)
                {
                    definedValues.Add(columnRefBinding.ValueDefinition);
                }

                TableAlgebraNode algebraNode = new TableAlgebraNode();
                algebraNode.TableRefBinding = node.TableRefBinding;
                algebraNode.DefinedValues   = definedValues.ToArray();
                SetLastAlgebraNode(algebraNode);
            }
            else
            {
                // It is a reference to a CTE. Instead of emitting a table node we have to replace the
                // reference to the CTE by the algebrized representation of the CTE. One could speak
                // of "inlining" the CTE.

                if (tableBindingAsCommonTable == _currentCommonTableBinding)
                {
                    // This should never happen. The JoinAlgebraNode should ignore these table references.
                    Debug.Fail("The current common table binding should never be reached as a table reference.");
                }

                AlgebraNode algebrizedCte;
                if (tableBindingAsCommonTable.IsRecursive)
                {
                    algebrizedCte = AlgebrizeRecursiveCte(tableBindingAsCommonTable);
                }
                else
                {
                    algebrizedCte = Convert(tableBindingAsCommonTable.AnchorMember);
                }

                // In order to use the CTE we have to instantiate it. See commonets in InstantiateCte() for
                // details.

                AlgebraNode computeScalarAlgebraNode = InstantiateCte(algebrizedCte, tableBindingAsCommonTable, node.TableRefBinding);
                SetLastAlgebraNode(computeScalarAlgebraNode);
            }

            return(node);
        }
Esempio n. 8
0
        public override AlgebraNode VisitTableAlgebraNode(TableAlgebraNode node)
        {
            PropertyListBuilder propertyListBuilder = new PropertyListBuilder();

            propertyListBuilder.Write(Resources.ShowPlanKeyTable, String.Format(CultureInfo.InvariantCulture, "{0} AS {1}", node.TableRefBinding.TableBinding.Name, node.TableRefBinding.Name));
            AddRowBufferEntries(propertyListBuilder, Resources.ShowPlanGroupOutputList, node.OutputList);
            AddStatistics(propertyListBuilder, node.StatisticsIterator);

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

            ShowPlanElement element = new ShowPlanElement(ShowPlanOperator.TableScan, properties);

            _currentElement = element;

            return(node);
        }
Esempio n. 9
0
            public override AlgebraNode VisitTableAlgebraNode(TableAlgebraNode node)
            {
                TableRefBinding oldTableRefBinding = node.TableRefBinding;
                TableRefBinding newTableRefBinding = new TableRefBinding(oldTableRefBinding.Scope, oldTableRefBinding.TableBinding, oldTableRefBinding.Name);

                List <ColumnValueDefinition> definedValues = new List <ColumnValueDefinition>();

                for (int i = 0; i < newTableRefBinding.ColumnRefs.Length; i++)
                {
                    definedValues.Add(newTableRefBinding.ColumnRefs[i].ValueDefinition);
                    RowBufferEntry oldRowBufferEntry = oldTableRefBinding.ColumnRefs[i].ValueDefinition.Target;
                    RowBufferEntry newRowBufferEntry = newTableRefBinding.ColumnRefs[i].ValueDefinition.Target;
                    _rowBufferMappings.Add(oldRowBufferEntry, newRowBufferEntry);
                }

                node.TableRefBinding = newTableRefBinding;
                node.DefinedValues   = definedValues.ToArray();

                return(node);
            }
Esempio n. 10
0
		public override AlgebraNode VisitTableAlgebraNode(TableAlgebraNode node)
		{
			AddDefinedValues(node.DefinedValues);

			return node;
		}
Esempio n. 11
0
		public override AlgebraNode VisitTableAlgebraNode(TableAlgebraNode node)
		{
			_xmlWriter.WriteStartElement("tableAlgebraNode");
			WriteTableRef(node.TableRefBinding);

			_xmlWriter.WriteEndElement();

			return node;
		}
Esempio n. 12
0
 public virtual AlgebraNode VisitTableAlgebraNode(TableAlgebraNode node)
 {
     return(node);
 }
Esempio n. 13
0
			public override AlgebraNode VisitTableAlgebraNode(TableAlgebraNode node)
			{
				TableRefBinding oldTableRefBinding = node.TableRefBinding;
				TableRefBinding newTableRefBinding = new TableRefBinding(oldTableRefBinding.Scope, oldTableRefBinding.TableBinding, oldTableRefBinding.Name);

				List<ColumnValueDefinition> definedValues = new List<ColumnValueDefinition>();
				for (int i = 0; i < newTableRefBinding.ColumnRefs.Length; i++)
				{
					definedValues.Add(newTableRefBinding.ColumnRefs[i].ValueDefinition);
					RowBufferEntry oldRowBufferEntry = oldTableRefBinding.ColumnRefs[i].ValueDefinition.Target;
					RowBufferEntry newRowBufferEntry = newTableRefBinding.ColumnRefs[i].ValueDefinition.Target;
					_rowBufferMappings.Add(oldRowBufferEntry, newRowBufferEntry);
				}

				node.TableRefBinding = newTableRefBinding;
				node.DefinedValues = definedValues.ToArray();

				return node;
			}
Esempio n. 14
0
		public override TableReference VisitNamedTableReference(NamedTableReference node)
		{
			CommonTableBinding tableBindingAsCommonTable = node.TableRefBinding.TableBinding as CommonTableBinding;

			if (tableBindingAsCommonTable == null)
			{
				// It is a regular table reference. Emit just a table node.

				List<ColumnValueDefinition> definedValues = new List<ColumnValueDefinition>();
				foreach (ColumnRefBinding columnRefBinding in node.TableRefBinding.ColumnRefs)
					definedValues.Add(columnRefBinding.ValueDefinition);

				TableAlgebraNode algebraNode = new TableAlgebraNode();
				algebraNode.TableRefBinding = node.TableRefBinding;
				algebraNode.DefinedValues = definedValues.ToArray();
				SetLastAlgebraNode(algebraNode);
			}
			else
			{
				// It is a reference to a CTE. Instead of emitting a table node we have to replace the
				// reference to the CTE by the algebrized representation of the CTE. One could speak
				// of "inlining" the CTE.

				if (tableBindingAsCommonTable == _currentCommonTableBinding)
				{
					// This should never happen. The JoinAlgebraNode should ignore these table references.
					Debug.Fail("The current common table binding should never be reached as a table reference.");
				}

				AlgebraNode algebrizedCte;
				if (tableBindingAsCommonTable.IsRecursive)
					algebrizedCte = AlgebrizeRecursiveCte(tableBindingAsCommonTable);
				else
					algebrizedCte = Convert(tableBindingAsCommonTable.AnchorMember);

				// In order to use the CTE we have to instantiate it. See commonets in InstantiateCte() for
				// details.

				AlgebraNode computeScalarAlgebraNode = InstantiateCte(algebrizedCte, tableBindingAsCommonTable, node.TableRefBinding);
				SetLastAlgebraNode(computeScalarAlgebraNode);
			}

			return node;
		}
Esempio n. 15
0
 public override AlgebraNode VisitTableAlgebraNode(TableAlgebraNode node)
 {
     _tables.Add(node);
     return(node);
 }
Esempio n. 16
0
        public override AlgebraNode VisitTableAlgebraNode(TableAlgebraNode node)
        {
            AddDefinedValues(node.DefinedValues);

            return(node);
        }
Esempio n. 17
0
			public override AlgebraNode VisitTableAlgebraNode(TableAlgebraNode node)
			{
				_tables.Add(node);
				return node;
			}
Esempio n. 18
0
 public override AlgebraNode VisitTableAlgebraNode(TableAlgebraNode node)
 {
     node.OutputList = GetRowBufferEntries(node.DefinedValues);
     return node;
 }
Esempio n. 19
0
 public override AlgebraNode VisitTableAlgebraNode(TableAlgebraNode node)
 {
     node.OutputList = GetRowBufferEntries(node.DefinedValues);
     return(node);
 }
Esempio n. 20
0
		public override AlgebraNode VisitTableAlgebraNode(TableAlgebraNode node)
		{
			List<RuntimeColumnValueOutput> definedValues = new List<RuntimeColumnValueOutput>();
			foreach (ColumnValueDefinition columnValueDefinition in node.DefinedValues)
			{
				RuntimeColumnValueOutput definedValue = new RuntimeColumnValueOutput();
				definedValue.TargetIndex = definedValues.Count;
				definedValue.ColumnBinding = columnValueDefinition.ColumnRefBinding.ColumnBinding;
				definedValues.Add(definedValue);
			}

			TableIterator tableIterator = new TableIterator();
			tableIterator.RowBuffer = new object[node.OutputList.Length];
			tableIterator.DefinedValues = definedValues.ToArray();
			tableIterator.Table = node.TableRefBinding.TableBinding;
			SetLastIterator(node, tableIterator);

			return node;
		}
Esempio n. 21
0
		public virtual AlgebraNode VisitTableAlgebraNode(TableAlgebraNode node)
		{
			return node;
		}
Esempio n. 22
0
        public override AlgebraNode VisitJoinAlgebraNode(JoinAlgebraNode node)
        {
            // Check if node only consists of INNER join nodes and simple table reference nodes.
            // This algorithm assumes that the table references have been lineraized so that
            //
            // - JoinedTableReference appear on the LHS only (the last one must be NamedTableReference ovbiviously)
            // - NamedTableReference appear on the RHS only
            //
            // While scanning the node's children we create a list of all JoinedTableReferences and
            // NamedTableReferences.

            InnerJoinTableExtractor innerJoinTableExtractor = new InnerJoinTableExtractor();

            innerJoinTableExtractor.Visit(node);

            if (!innerJoinTableExtractor.ConsistsOnlyOfInnerJoinsFiltersAndTables)
            {
                node.Left  = VisitAlgebraNode(node.Left);
                node.Right = VisitAlgebraNode(node.Right);
                return(node);
            }
            else
            {
                TableAlgebraNode[] algebraNodes = innerJoinTableExtractor.GetTableNodes();
                Dictionary <TableRefBinding, TableAlgebraNode> tableRefToNodeDictionary = new Dictionary <TableRefBinding, TableAlgebraNode>();
                List <TableRefBinding> tableList = new List <TableRefBinding>();
                foreach (TableAlgebraNode algebraNode in algebraNodes)
                {
                    tableRefToNodeDictionary.Add(algebraNode.TableRefBinding, algebraNode);
                    tableList.Add(algebraNode.TableRefBinding);
                }

                // Create a mapping RowBufferEntry -> ColumnRefBinding

                Dictionary <RowBufferEntry, ColumnRefBinding> rowBufferColumnDictionary = new Dictionary <RowBufferEntry, ColumnRefBinding>();
                foreach (TableRefBinding tableRefBinding in tableList)
                {
                    foreach (ColumnRefBinding columnRefBinding in tableRefBinding.ColumnRefs)
                    {
                        rowBufferColumnDictionary.Add(columnRefBinding.ValueDefinition.Target, columnRefBinding);
                    }
                }

                // Create list of all possible join conditions and remaining AND-parts.

                List <JoinCondition>  joinConditionList = new List <JoinCondition>();
                List <ExpressionNode> andPartList       = new List <ExpressionNode>();

                ExpressionNode filter = AstUtil.CombineConditions(LogicalOperator.And, innerJoinTableExtractor.GetFilters());

                foreach (ExpressionNode andPart in AstUtil.SplitCondition(LogicalOperator.And, filter))
                {
                    JoinCondition joinCondition = ConvertToJoinCondition(rowBufferColumnDictionary, andPart);

                    if (joinCondition != null)
                    {
                        joinConditionList.Add(joinCondition);
                    }
                    else
                    {
                        andPartList.Add(andPart);
                    }
                }

                // After creating the list of all join conditions and AND-parts we have all we need to create
                // an optimimal join order between all tables of this part of the table tree.
                JoinOrder bestJoinOrder = GetBestJoinOrder(tableList.ToArray(), joinConditionList.ToArray(), andPartList.ToArray());

                // Get all tables that are introduced by this join order

                Dictionary <RowBufferEntry, ColumnValueDefinition> introducedColumns = GetIntroducedColumns(bestJoinOrder);

                // Combine AND-part list with all unused join conditions.

                andPartList.AddRange(bestJoinOrder.UnusedConditions);

                // Now we will re-create this part of the tree using the this join order.

                AlgebraNode lastAlgebraNode = null;
                for (int joinIndex = 0; joinIndex < bestJoinOrder.Joins.Length; joinIndex++)
                {
                    Join join = bestJoinOrder.Joins[joinIndex];

                    AlgebraNode      tableInput;
                    TableAlgebraNode tableNode = tableRefToNodeDictionary[join.TableRefBinding];

                    ExpressionNode tableFilter = ExtractConditionsApplicableToTable(introducedColumns, andPartList, join.TableRefBinding);
                    if (tableFilter == null)
                    {
                        tableInput = tableNode;
                    }
                    else
                    {
                        FilterAlgebraNode filterAlgebraNode = new FilterAlgebraNode();
                        filterAlgebraNode.Input     = tableNode;
                        filterAlgebraNode.Predicate = tableFilter;
                        tableInput = filterAlgebraNode;
                    }

                    if (lastAlgebraNode == null)
                    {
                        // This was the first one.
                        lastAlgebraNode = tableInput;
                    }
                    else
                    {
                        // Not the first one, we can create a join with the current table reference
                        // and last table reference.

                        // Get all AND-parts that can be applied to the tables already joined.
                        // This expression is merged to one condition.
                        ExpressionNode[] applicableAndParts = GetAndPartsApplicableToJoin(introducedColumns, bestJoinOrder, joinIndex, andPartList, true);
                        ExpressionNode   condition          = AstUtil.CombineConditions(LogicalOperator.And, applicableAndParts);

                        ExpressionNode joinCondition;
                        if (join.JoinCondition == null)
                        {
                            joinCondition = null;
                        }
                        else
                        {
                            joinCondition = join.JoinCondition.ToExpression();
                        }

                        ExpressionNode completeCondition = AstUtil.CombineConditions(LogicalOperator.And, condition, joinCondition);

                        JoinAlgebraNode joinAlgebraNode = new JoinAlgebraNode();
                        joinAlgebraNode.Op        = JoinAlgebraNode.JoinOperator.InnerJoin;
                        joinAlgebraNode.Left      = lastAlgebraNode;
                        joinAlgebraNode.Right     = tableInput;
                        joinAlgebraNode.Predicate = completeCondition;

                        // Next time this newly created join is the last table reference.
                        lastAlgebraNode = joinAlgebraNode;
                    }
                }

                return(lastAlgebraNode);
            }
        }
Esempio n. 23
0
        public override AlgebraNode VisitTableAlgebraNode(TableAlgebraNode node)
        {
            PropertyListBuilder propertyListBuilder = new PropertyListBuilder();
            propertyListBuilder.Write(Resources.ShowPlanKeyTable, String.Format(CultureInfo.InvariantCulture, "{0} AS {1}", node.TableRefBinding.TableBinding.Name, node.TableRefBinding.Name));
            AddRowBufferEntries(propertyListBuilder, Resources.ShowPlanGroupOutputList, node.OutputList);
            AddStatistics(propertyListBuilder, node.StatisticsIterator);

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

            ShowPlanElement element = new ShowPlanElement(ShowPlanOperator.TableScan, properties);
            _currentElement = element;

            return node;
        }