From e68124b4d5bcae2831ecb5a7f856c33ae4528bc7 Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Mon, 11 Jul 2022 14:05:20 -0700 Subject: [PATCH] Adding more top operations columns and fixing some column values (#1571) * Adding more rules for prop * adding top operations to ep * Reverting changes made to display cost * Fixing comments * Removing whitespace * Fixing data size property * Adding const keys, fixing to table data, adding more info * Removing undeclared prop --- .../ExecutionPlan/ExecutionPlanGraphUtils.cs | 112 +++++++++++++----- .../ExecutionPlan/ShowPlan/Node.cs | 8 +- .../Localization/sr.cs | 6 +- .../Localization/sr.resx | 8 +- .../Localization/sr.strings | 4 +- .../Localization/sr.xlf | 10 +- 6 files changed, 101 insertions(+), 47 deletions(-) diff --git a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ExecutionPlanGraphUtils.cs b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ExecutionPlanGraphUtils.cs index e49760b8..eef9d51a 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ExecutionPlanGraphUtils.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ExecutionPlanGraphUtils.cs @@ -165,7 +165,24 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan } public static List ParseTopOperationsData(Node currentNode) - { + { + const string OBJECT_COLUMN_KEY = "Object"; + const string ESTIMATED_ROWS_COLUMN_KEY = "EstimateRows"; + const string ACTUAL_ROWS_COLUMN_KEY = "ActualRows"; + const string AVERAGE_ROW_SIZE_COLUMN_KEY = "AvgRowSize"; + const string ACTUAL_EXECUTIONS_COLUMN_KEY = "ActualExecutions"; + const string ESTIMATED_EXECUTIONS_COLUMN_KEY = "EstimateExecutions"; + const string ESTIMATED_CPU_COLUMN_KEY = "EstimateCPU"; + const string ESTIMATED_IO_COLUMN_KEY = "EstimateIO"; + const string PARALLEL_COLUMN_KEY = "Parallel"; + const string ORDERED_COLUMN_KEY = "Ordered"; + const string ACTUAL_REWINDS_COLUMN_KEY = "ActualRewinds"; + const string ESTIMATED_REWINDS_COLUMN_KEY = "EstimateRewinds"; + const string ACTUAL_REBINDS_COLUMN_KEY = "ActualRebinds"; + const string ESTIMATED_REBINDS_COLUMN_KEY = "EstimateRebinds"; + const string PARTITIONED_COLUMN_KEY = "Partitioned"; + + List result = new List(); result.Add(new TopOperationsDataItem { @@ -174,13 +191,13 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan DisplayValue = currentNode.Operation.DisplayName }); - if (currentNode["Object"] != null) + if (currentNode[OBJECT_COLUMN_KEY] != null) { result.Add(new TopOperationsDataItem { ColumnName = SR.Object, DataType = PropertyValueDataType.String, - DisplayValue = ((ExpandableObjectWrapper)currentNode["Object"]).DisplayName + DisplayValue = ((ExpandableObjectWrapper)currentNode[OBJECT_COLUMN_KEY]).DisplayName }); } @@ -188,7 +205,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan { ColumnName = SR.EstimatedCost, DataType = PropertyValueDataType.Number, - DisplayValue = Math.Round(currentNode.Cost, 1) + DisplayValue = Math.Round(currentNode.RelativeCost * 100, 2) }); result.Add(new TopOperationsDataItem @@ -198,134 +215,165 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan DisplayValue = Math.Round(currentNode.SubtreeCost, 1) }); - if (currentNode["ActualRows"] != null) + if (currentNode[ESTIMATED_ROWS_COLUMN_KEY] != null) + { + result.Add(new TopOperationsDataItem + { + ColumnName = SR.EstimatedRows, + DataType = PropertyValueDataType.Number, + DisplayValue = Math.Round((double)currentNode[ESTIMATED_ROWS_COLUMN_KEY]) + }); + } + + + if (currentNode[ACTUAL_ROWS_COLUMN_KEY] != null) { result.Add(new TopOperationsDataItem { ColumnName = SR.ActualRows, DataType = PropertyValueDataType.Number, - DisplayValue = currentNode["ActualRows"] + DisplayValue = currentNode[ACTUAL_ROWS_COLUMN_KEY] }); } - if (currentNode["AvgRowSize"] != null) + if (currentNode[AVERAGE_ROW_SIZE_COLUMN_KEY] != null) { result.Add(new TopOperationsDataItem { - ColumnName = SR.EstimatedAverageRowSize, + ColumnName = SR.AverageRowSize, DataType = PropertyValueDataType.Number, - DisplayValue = currentNode["AvgRowSize"] + DisplayValue = currentNode[AVERAGE_ROW_SIZE_COLUMN_KEY] }); } - if (currentNode["ActualExecutions"] != null) + if (currentNode[ACTUAL_EXECUTIONS_COLUMN_KEY] != null) { result.Add(new TopOperationsDataItem { ColumnName = SR.ActualExecutions, DataType = PropertyValueDataType.Number, - DisplayValue = currentNode["ActualExecutions"] + DisplayValue = currentNode[ACTUAL_EXECUTIONS_COLUMN_KEY] }); } - if (currentNode["EstimateExecutions"] != null) + if (currentNode[ESTIMATED_EXECUTIONS_COLUMN_KEY] != null) { result.Add(new TopOperationsDataItem { ColumnName = SR.EstimatedExecutions, DataType = PropertyValueDataType.Number, - DisplayValue = currentNode["EstimateExecutions"] + DisplayValue = currentNode[ESTIMATED_EXECUTIONS_COLUMN_KEY] }); } - if (currentNode["EstimateCPU"] != null) + if (currentNode[ESTIMATED_CPU_COLUMN_KEY] != null) { result.Add(new TopOperationsDataItem { ColumnName = SR.EstimatedCpu, DataType = PropertyValueDataType.Number, - DisplayValue = currentNode["EstimateCPU"] + DisplayValue = currentNode[ESTIMATED_CPU_COLUMN_KEY] }); } - if (currentNode["EstimateIO"] != null) + if (currentNode[ESTIMATED_IO_COLUMN_KEY] != null) { result.Add(new TopOperationsDataItem { ColumnName = SR.EstimatedIO, DataType = PropertyValueDataType.Number, - DisplayValue = currentNode["EstimateIO"] + DisplayValue = currentNode[ESTIMATED_IO_COLUMN_KEY] }); } - if (currentNode["Parallel"] != null) + if (currentNode[ESTIMATED_ROWS_COLUMN_KEY] != null && currentNode[AVERAGE_ROW_SIZE_COLUMN_KEY] != null) + { + result.Add(new TopOperationsDataItem + { + ColumnName = SR.EstimatedDataSize, + DataType = PropertyValueDataType.Number, + DisplayValue = (double)currentNode[ESTIMATED_ROWS_COLUMN_KEY] * (double)currentNode[AVERAGE_ROW_SIZE_COLUMN_KEY] + }); + } + + + if (currentNode[ACTUAL_ROWS_COLUMN_KEY] != null && currentNode[AVERAGE_ROW_SIZE_COLUMN_KEY] != null) + { + result.Add(new TopOperationsDataItem + { + ColumnName = SR.ActualDataSize, + DataType = PropertyValueDataType.Number, + DisplayValue = (double)(currentNode[ACTUAL_ROWS_COLUMN_KEY] as RunTimeCounters).MaxCounter * (double)currentNode[AVERAGE_ROW_SIZE_COLUMN_KEY] + }); + } + + if (currentNode[PARALLEL_COLUMN_KEY] != null) { result.Add(new TopOperationsDataItem { ColumnName = SR.Parallel, DataType = PropertyValueDataType.Boolean, - DisplayValue = currentNode["Parallel"] + DisplayValue = currentNode[PARALLEL_COLUMN_KEY] }); } - if (currentNode["Ordered"] != null) + if (currentNode[ORDERED_COLUMN_KEY] != null) { result.Add(new TopOperationsDataItem { ColumnName = SR.Ordered, DataType = PropertyValueDataType.Boolean, - DisplayValue = currentNode["Ordered"] + DisplayValue = currentNode[ORDERED_COLUMN_KEY] }); } - if (currentNode["ActualRewinds"] != null) + if (currentNode[ACTUAL_REWINDS_COLUMN_KEY] != null) { result.Add(new TopOperationsDataItem { ColumnName = SR.ActualRewinds, DataType = PropertyValueDataType.Number, - DisplayValue = currentNode["ActualRewinds"] + DisplayValue = currentNode[ACTUAL_REWINDS_COLUMN_KEY] }); } - if (currentNode["EstimateRewinds"] != null) + if (currentNode[ESTIMATED_REWINDS_COLUMN_KEY] != null) { result.Add(new TopOperationsDataItem { ColumnName = SR.EstimatedRewinds, DataType = PropertyValueDataType.Number, - DisplayValue = currentNode["EstimateRewinds"] + DisplayValue = currentNode[ESTIMATED_REWINDS_COLUMN_KEY] }); } - if (currentNode["ActualRebinds"] != null) + if (currentNode[ACTUAL_REBINDS_COLUMN_KEY] != null) { result.Add(new TopOperationsDataItem { ColumnName = SR.ActualRebinds, DataType = PropertyValueDataType.Number, - DisplayValue = currentNode["ActualRebinds"] + DisplayValue = currentNode[ACTUAL_REBINDS_COLUMN_KEY] }); } - - if (currentNode["EstimateRebinds"] != null) + if (currentNode[ESTIMATED_REBINDS_COLUMN_KEY] != null) { result.Add(new TopOperationsDataItem { ColumnName = SR.EstimatedRebinds, DataType = PropertyValueDataType.Number, - DisplayValue = currentNode["EstimateRebinds"] + DisplayValue = currentNode[ESTIMATED_REBINDS_COLUMN_KEY] }); } - if (currentNode["Partitioned"] != null) + if (currentNode[PARTITIONED_COLUMN_KEY] != null) { result.Add(new TopOperationsDataItem { ColumnName = SR.Partitioned, DataType = PropertyValueDataType.Boolean, - DisplayValue = currentNode["Partitioned"] + DisplayValue = currentNode[PARTITIONED_COLUMN_KEY] }); } return result; diff --git a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/Node.cs b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/Node.cs index 663aa511..25163cf4 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/Node.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/Node.cs @@ -590,7 +590,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan if (!this.HasPDWCost || cost > 0) { - if (roundCostForSmallGraph && this.graph != null && this.graph.NodeStmtMap.Count < 20) + if (roundCostForSmallGraph && this.graph != null && this.graph.NodeStmtMap.Count < Node.LargePlanNodeCount) { cost = Math.Round(cost); } @@ -732,6 +732,12 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan #endregion + #region Constants + + public static readonly int LargePlanNodeCount = 20; + + #endregion + public void AddChild(Node child) { Edge edge = new Edge(this, child); diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs index a1c6b4f6..5f98fa99 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs @@ -8565,11 +8565,11 @@ namespace Microsoft.SqlTools.ServiceLayer } } - public static string EstimatedAverageRowSize + public static string AverageRowSize { get { - return Keys.GetString(Keys.EstimatedAverageRowSize); + return Keys.GetString(Keys.AverageRowSize); } } @@ -13076,7 +13076,7 @@ namespace Microsoft.SqlTools.ServiceLayer public const string EstimatedIO = "EstimatedIO"; - public const string EstimatedAverageRowSize = "EstimatedAverageRowSize"; + public const string AverageRowSize = "AverageRowSize"; public const string ActualDataSize = "ActualDataSize"; diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx index 7be96b4f..32650a4a 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx @@ -4618,7 +4618,7 @@ Parameters: 0 - cost (double), 1 - percentage (int) - {0} of + {0} of {1} ({2}%) . Parameters: 0 - actual (string), 1 - estimated (string), 2 - percent (decimal) @@ -4657,7 +4657,7 @@ The Query Processor estimates that implementing the following index could improv - Estimated Subtree Cost % + Estimated Subtree Cost @@ -4684,8 +4684,8 @@ The Query Processor estimates that implementing the following index could improv Estimated IO Cost - - Estimated Average Row Size + + Average Row Size diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings index 5b91fb02..0e07856b 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings @@ -2240,14 +2240,14 @@ ParallelismOverlayTooltip = Parallel Execution Operation = Operation Object = Object EstimatedCost = Estimated Cost % -EstimatedSubtree = Estimated Subtree Cost % +EstimatedSubtree = Estimated Subtree Cost ActualRows = Actual Rows EstimatedRows = Estimated Rows ActualExecutions = Actual Executions EstimatedExecutions = Estimated Executions EstimatedCpu = Estimated CPU Cost EstimatedIO = Estimated IO Cost -EstimatedAverageRowSize = Estimated Average Row Size +AverageRowSize = Average Row Size ActualDataSize = Actual Data Size ############################################################################ diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf index cf942381..1389dcf5 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf @@ -6210,8 +6210,8 @@ The Query Processor estimates that implementing the following index could improv - Estimated Subtree Cost % - Estimated Subtree Cost % + Estimated Subtree Cost + Estimated Subtree Cost @@ -6249,9 +6249,9 @@ The Query Processor estimates that implementing the following index could improv Actual Data Size - - Estimated Average Row Size - Estimated Average Row Size + + Average Row Size + Average Row Size