コード例 #1
0
 /// <summary>
 /// Span the table given the edge using cross apply
 /// </summary>
 /// <param name="tableRef"></param>
 /// <param name="edge"></param>
 /// <param name="nodeAlias"></param>
 /// <returns></returns>
 public static WTableReference SpanTableRef(WTableReference tableRef, MatchEdge edge, string nodeAlias)
 {
     tableRef = new WUnqualifiedJoin
     {
         FirstTableRef       = tableRef,
         SecondTableRef      = EdgeToTableReference(edge, nodeAlias),
         UnqualifiedJoinType = UnqualifiedJoinType.CrossApply,
     };
     return(tableRef);
 }
コード例 #2
0
 /// <summary>
 /// Span the table given the edge using cross apply
 /// </summary>
 /// <param name="tableRef"></param>
 /// <param name="edge"></param>
 /// <param name="nodeAlias"></param>
 /// <returns></returns>
 public WTableReference SpanTableRef(WTableReference tableRef, MatchEdge edge, string nodeAlias, GraphMetaData metaData)
 {
     tableRef = new WUnqualifiedJoin
     {
         FirstTableRef       = tableRef,
         SecondTableRef      = edge.ToSchemaObjectFunction(nodeAlias, metaData),
         UnqualifiedJoinType = UnqualifiedJoinType.CrossApply,
     };
     return(tableRef);
 }
コード例 #3
0
        private static WTableReference ConstructUpSizeTableReference(WTableReference tableRef, double upSizeScalar, out double affectedEstimatedSize)
        {
            affectedEstimatedSize = 1.0;
            int pow         = (int)(Math.Floor(Math.Log(upSizeScalar, 1000)) + 1);
            int adjustValue = (int)Math.Pow(upSizeScalar, 1.0 / pow);

            while (pow > 0)
            {
                tableRef = new WUnqualifiedJoin
                {
                    FirstTableRef  = tableRef,
                    SecondTableRef = new WSchemaObjectFunctionTableReference
                    {
                        SchemaObject = new WSchemaObjectName(
                            new Identifier {
                            Value = "dbo"
                        },
                            new Identifier {
                            Value = "UpSizeFunction"
                        }),
                        Parameters = new List <WScalarExpression>
                        {
                            new WValueExpression {
                                Value = adjustValue.ToString()
                            }
                        },
                        Alias = new Identifier
                        {
                            Value = Path.GetRandomFileName().Replace(".", "").Substring(0, 8),
                        }
                    },
                    UnqualifiedJoinType = UnqualifiedJoinType.CrossApply
                };
                pow--;
                affectedEstimatedSize *= adjustValue;
            }
            return(tableRef);
        }
コード例 #4
0
ファイル: WSqlParser.cs プロジェクト: Coword/GraphView
        private WTableReference ParseTableReference(TableReference tabRef)
        {
            if (tabRef == null)
            {
                return null;
            }
            var tabRefWithAlias = tabRef as TableReferenceWithAlias;
            if (tabRefWithAlias!=null && tabRefWithAlias.Alias!=null &&
                 GraphViewKeywords._keywords.Contains(tabRefWithAlias.Alias.Value))
            {
                var token = _tokens[tabRefWithAlias.Alias.FirstTokenIndex];
                throw new SyntaxErrorException(token.Line, tabRefWithAlias.Alias.Value,
                    "System restricted Name cannot be used");
            }
            switch (tabRef.GetType().Name)
            {
                case "NamedTableReference":
                    {
                        var oref = tabRef as NamedTableReference;
                        if (oref.SchemaObject.BaseIdentifier.QuoteType == QuoteType.NotQuoted &&
                            (oref.SchemaObject.BaseIdentifier.Value[0] == '@' ||
                             oref.SchemaObject.BaseIdentifier.Value[0] == '#'))
                        {
                            var pref = new WSpecialNamedTableReference
                            {
                                Alias = oref.Alias,
                                TableHints = new List<WTableHint>(),
                                FirstTokenIndex = oref.FirstTokenIndex,
                                LastTokenIndex = oref.LastTokenIndex,
                                TableObjectName = ParseSchemaObjectName(oref.SchemaObject),
                            };

                            if (oref.TableHints != null)
                            {
                                foreach (var hint in oref.TableHints)
                                    pref.TableHints.Add(ParseTableHint(hint));
                            }

                            return pref;
                        }
                        else
                        {
                            var pref = new WNamedTableReference
                            {
                                Alias = oref.Alias,
                                TableHints = new List<WTableHint>(),
                                FirstTokenIndex = oref.FirstTokenIndex,
                                LastTokenIndex = oref.LastTokenIndex,
                                TableObjectName = ParseSchemaObjectName(oref.SchemaObject),
                            };

                            if (oref.TableHints != null)
                            {
                                foreach (var hint in oref.TableHints)
                                    pref.TableHints.Add(ParseTableHint(hint));
                            }

                            return pref;
                        }
                    }
                case "QueryDerivedTable":
                    {
                        var oref = tabRef as QueryDerivedTable;
                        var pref = new WQueryDerivedTable
                        {
                            QueryExpr = ParseSelectQueryStatement(oref.QueryExpression),
                            Alias = oref.Alias,
                            Columns = oref.Columns,
                            FirstTokenIndex = oref.FirstTokenIndex,
                            LastTokenIndex = oref.LastTokenIndex,
                        };

                        return pref;
                    }
                case "SchemaObjectFunctionTableReference":
                    {
                        var oref = tabRef as SchemaObjectFunctionTableReference;
                        var pref = new WSchemaObjectFunctionTableReference
                        {
                            Alias = oref.Alias,
                            Columns = oref.Columns,
                            SchemaObject = ParseSchemaObjectName(oref.SchemaObject),
                            FirstTokenIndex = oref.FirstTokenIndex,
                            LastTokenIndex = oref.LastTokenIndex
                        };
                        if (oref.Parameters == null)
                            return pref;
                        pref.Parameters = new List<WScalarExpression>();
                        foreach (var param in oref.Parameters)
                            pref.Parameters.Add(ParseScalarExpression(param));
                        return pref;
                    }
                case "QualifiedJoin":
                    {
                        var oref = tabRef as QualifiedJoin;
                        var pref = new WQualifiedJoin
                        {
                            FirstTableRef = ParseTableReference(oref.FirstTableReference),
                            SecondTableRef = ParseTableReference(oref.SecondTableReference),
                            QualifiedJoinType = oref.QualifiedJoinType,
                            JoinHint = oref.JoinHint,
                            JoinCondition = ParseBooleanExpression(oref.SearchCondition),
                            FirstTokenIndex = oref.FirstTokenIndex,
                            LastTokenIndex = oref.LastTokenIndex,
                        };

                        return pref;
                    }
                case "UnqualifiedJoin":
                    {
                        var oref = tabRef as UnqualifiedJoin;
                        var pref = new WUnqualifiedJoin
                        {
                            FirstTableRef = ParseTableReference(oref.FirstTableReference),
                            SecondTableRef = ParseTableReference(oref.SecondTableReference),
                            UnqualifiedJoinType = oref.UnqualifiedJoinType,
                            FirstTokenIndex = oref.FirstTokenIndex,
                            LastTokenIndex = oref.LastTokenIndex,
                        };
                        return pref;
                    }
                case "JoinParenthesisTableReference":
                    {
                        var ptab = tabRef as JoinParenthesisTableReference;

                        var wptab = new WParenthesisTableReference
                        {
                            Table = ParseTableReference(ptab.Join),
                            FirstTokenIndex = ptab.FirstTokenIndex,
                            LastTokenIndex = ptab.LastTokenIndex,
                        };

                        return wptab;
                    }
                default:
                    return null;
            }
        }
コード例 #5
0
        /// <summary>
        /// Calculate the number used for adjusting the SQL Server estimation in the downsize function.
        /// </summary>
        /// <param name="component"></param>
        /// <param name="tablfRef"></param>
        /// <param name="joinTable"></param>
        /// <param name="size"></param>
        /// <param name="estimatedSize"></param>
        /// <param name="shrinkSize"></param>
        /// <param name="joinTableTuple"></param>
        private static void AdjustEstimation(
            MatchComponent component,
            WTableReference tablfRef,
            WQualifiedJoin joinTable,
            double size,
            double estimatedSize,
            double shrinkSize,
            Tuple <WQualifiedJoin, String> joinTableTuple)
        {
            const int sizeFactor     = 10;
            int       estimateFactor = 0;

            if (size > sizeFactor * estimatedSize)
            {
                estimateFactor = (int)Math.Ceiling(size / estimatedSize);
            }
            else if (sizeFactor * size < estimatedSize)
            {
                estimatedSize          /= shrinkSize;
                component.EstimateSize /= shrinkSize;
                component.FatherListofDownSizeTable.Add(joinTableTuple);
                estimateFactor = (int)Math.Ceiling(size / estimatedSize);
            }
            if (estimateFactor > 1)
            {
                WTableReference crossApplyTable = tablfRef;
                int             pow             = (int)(Math.Floor(Math.Log(estimateFactor, 1000)) + 1);
                int             adjustValue     = (int)Math.Pow(estimateFactor, 1.0 / pow);
                while (pow > 0)
                {
                    crossApplyTable = new WUnqualifiedJoin
                    {
                        FirstTableRef  = crossApplyTable,
                        SecondTableRef = new WSchemaObjectFunctionTableReference
                        {
                            SchemaObject = new WSchemaObjectName(
                                new Identifier {
                                Value = "dbo"
                            },
                                new Identifier {
                                Value = "UpSizeFunction"
                            }),
                            Parameters = new List <WScalarExpression>
                            {
                                new WValueExpression {
                                    Value = adjustValue.ToString()
                                }
                            },
                            Alias = new Identifier
                            {
                                Value = Path.GetRandomFileName().Replace(".", "").Substring(0, 8),
                            }
                        },
                        UnqualifiedJoinType = UnqualifiedJoinType.CrossApply
                    };
                    pow--;
                    component.EstimateSize *= adjustValue;
                }
                joinTable.FirstTableRef = crossApplyTable;
            }
        }
コード例 #6
0
ファイル: MatchComponent.cs プロジェクト: Microsoft/GraphView
 private static WTableReference ConstructUpSizeTableReference(WTableReference tableRef, double upSizeScalar, string dumb, DumbType dumbType, out double affectedEstimatedSize)
 {
     affectedEstimatedSize = 1.0;
     int pow = (int)(Math.Floor(Math.Log(upSizeScalar, 1000)) + 1);
     int adjustValue = (int)Math.Pow(upSizeScalar, 1.0 / pow);
     while (pow > 0)
     {
         tableRef = new WUnqualifiedJoin
         {
             FirstTableRef = tableRef,
             SecondTableRef = new WSchemaObjectFunctionTableReference
             {
                 SchemaObject = new WSchemaObjectName(
                     new Identifier { Value = "dbo" },
                     new Identifier { Value = "UpSizeFunction2" }),
                 Parameters = new List<WScalarExpression>
                 {
                     new WValueExpression {Value = adjustValue.ToString()},
                     new WColumnReferenceExpression
                     {
                         MultiPartIdentifier =
                             new WMultiPartIdentifier(
                                 new Identifier {Value = dumb},
                                 new Identifier {Value = dumbType == DumbType.Node ? "GlobalNodeId" : "Sink"})
                     }
                 },
                 Alias = new Identifier
                 {
                     Value = Path.GetRandomFileName().Replace(".", "").Substring(0, 8),
                 }
             },
             UnqualifiedJoinType = UnqualifiedJoinType.CrossApply
         };
         pow--;
         affectedEstimatedSize *= adjustValue;
     }
     return tableRef;
 }
コード例 #7
0
ファイル: MatchComponent.cs プロジェクト: Microsoft/GraphView
 /// <summary>
 /// Span the table given the edge using cross apply
 /// </summary>
 /// <param name="tableRef"></param>
 /// <param name="edge"></param>
 /// <param name="nodeAlias"></param>
 /// <param name="dumbNode"></param>
 /// <returns></returns>
 public WTableReference SpanTableRef(WTableReference tableRef, MatchEdge edge, string nodeAlias, string dumbNode, GraphMetaData metaData)
 {
     tableRef = new WUnqualifiedJoin
     {
         FirstTableRef = tableRef,
         SecondTableRef = edge.ToSchemaObjectFunction(nodeAlias, dumbNode, metaData),
         UnqualifiedJoinType = UnqualifiedJoinType.CrossApply,
     };
     return tableRef;
 }
コード例 #8
0
ファイル: MatchComponent.cs プロジェクト: champmit/GraphView
 /// <summary>
 /// Span the table given the edge using cross apply
 /// </summary>
 /// <param name="tableRef"></param>
 /// <param name="edge"></param>
 /// <param name="nodeAlias"></param>
 /// <returns></returns>
 public static WTableReference SpanTableRef(WTableReference tableRef, MatchEdge edge, string nodeAlias)
 {
     tableRef = new WUnqualifiedJoin
     {
         FirstTableRef = tableRef,
         SecondTableRef = EdgeToTableReference(edge, nodeAlias),
         UnqualifiedJoinType = UnqualifiedJoinType.CrossApply,
     };
     return tableRef;
 }
コード例 #9
0
ファイル: MatchComponent.cs プロジェクト: champmit/GraphView
 /// <summary>
 /// Calculate the number used for adjusting the SQL Server estimation in the downsize function.
 /// </summary>
 /// <param name="component"></param>
 /// <param name="tablfRef"></param>
 /// <param name="joinTable"></param>
 /// <param name="size"></param>
 /// <param name="estimatedSize"></param>
 /// <param name="shrinkSize"></param>
 /// <param name="joinTableTuple"></param>
 private static void AdjustEstimation(
     MatchComponent component,
     WTableReference tablfRef,
     WQualifiedJoin joinTable,
     double size,
     double estimatedSize,
     double shrinkSize,
     Tuple<WQualifiedJoin,String> joinTableTuple)
 {
     const int sizeFactor = 10;
     int estimateFactor = 0;
     if (size > sizeFactor*estimatedSize)
     {
         estimateFactor = (int)Math.Ceiling(size / estimatedSize);
     }
     else if (sizeFactor*size < estimatedSize)
     {
         estimatedSize /= shrinkSize;
         component.EstimateSize /= shrinkSize;
         component.FatherListofDownSizeTable.Add(joinTableTuple);
         estimateFactor = (int) Math.Ceiling(size/estimatedSize);
     }
     if (estimateFactor > 1)
     {
         WTableReference crossApplyTable = tablfRef;
         int pow = (int) (Math.Floor(Math.Log(estimateFactor, 1000)) + 1);
         int adjustValue = (int) Math.Pow(estimateFactor, 1.0/pow);
         while (pow > 0)
         {
             crossApplyTable = new WUnqualifiedJoin
             {
                 FirstTableRef = crossApplyTable,
                 SecondTableRef = new WSchemaObjectFunctionTableReference
                 {
                     SchemaObject = new WSchemaObjectName(
                         new Identifier {Value = "dbo"},
                         new Identifier {Value = "UpSizeFunction"}),
                     Parameters = new List<WScalarExpression>
                     {
                         new WValueExpression {Value = adjustValue.ToString()}
                     },
                     Alias = new Identifier
                     {
                         Value = Path.GetRandomFileName().Replace(".", "").Substring(0, 8),
                     }
                 },
                 UnqualifiedJoinType = UnqualifiedJoinType.CrossApply
             };
             pow--;
             component.EstimateSize *= adjustValue;
         }
         joinTable.FirstTableRef = crossApplyTable;
     }
 }