From a0390e81275ab31b5b840c009860f8a20a265b16 Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Thu, 6 Oct 2022 16:05:39 -0700 Subject: [PATCH] Adding new top operation column and comp rule for node id (#1719) * Adding actual cpu cost in top operations * Adding node id attribute --- .../ExecutionPlan/ExecutionPlanGraphUtils.cs | 24 +++++++++++++++++++ .../ExecutionPlan/ShowPlan/PropertyFactory.cs | 2 +- .../Localization/sr.cs | 11 +++++++++ .../Localization/sr.resx | 4 ++++ .../Localization/sr.strings | 1 + .../Localization/sr.xlf | 5 ++++ 6 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ExecutionPlanGraphUtils.cs b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ExecutionPlanGraphUtils.cs index 0e7c8d4b..4238c164 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ExecutionPlanGraphUtils.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ExecutionPlanGraphUtils.cs @@ -209,6 +209,8 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan const string ACTUAL_EXECUTIONS_COLUMN_KEY = "ActualExecutions"; const string ESTIMATED_EXECUTIONS_COLUMN_KEY = "EstimateExecutions"; const string ESTIMATED_CPU_COLUMN_KEY = "EstimateCPU"; + const string ACTUAL_TIME_STATS_KEY = "ActualTimeStatistics"; + const string ACTUAL_CPU_COLUMN_KEY = "ActualCPUms"; const string ESTIMATED_IO_COLUMN_KEY = "EstimateIO"; const string PARALLEL_COLUMN_KEY = "Parallel"; const string ORDERED_COLUMN_KEY = "Ordered"; @@ -312,6 +314,28 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan }); } + if (currentNode[ACTUAL_TIME_STATS_KEY] != null) + { + var actualStatsWrapper = currentNode[ACTUAL_TIME_STATS_KEY] as ExpandableObjectWrapper; + if (actualStatsWrapper != null) + { + var counters = actualStatsWrapper[ACTUAL_CPU_COLUMN_KEY] as RunTimeCounters; + if (counters != null) + { + var elapsedTime = counters.MaxCounter; + long ticks = (long)elapsedTime * TimeSpan.TicksPerMillisecond; + long time = new DateTime(ticks).Millisecond; + result.Add(new TopOperationsDataItem + { + ColumnName = SR.ActualCpu, + DataType = PropertyValueDataType.Number, + DisplayValue = time.ToString() + }); + } + } + + } + if (currentNode[ESTIMATED_IO_COLUMN_KEY] != null) { result.Add(new TopOperationsDataItem diff --git a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/PropertyFactory.cs b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/PropertyFactory.cs index 894dbbf6..56aea9b0 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/PropertyFactory.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/PropertyFactory.cs @@ -528,7 +528,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan [DisplayOrder(6), DisplayNameDescription(SR.Keys.OperationType)] public object OperationType { get { return null; } } - [ShowInToolTip, DisplayOrder(300), DisplayNameDescription(SR.Keys.NodeId)] + [ShowInToolTip, DisplayOrder(300), DisplayNameDescription(SR.Keys.NodeId), BetterValue(BetterValue.None)] public int NodeId { get { return 0; } } [ShowInToolTip, DisplayOrder(301), DisplayNameDescription(SR.Keys.PrimaryNodeId)] diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs index 0a6d17ac..13b1af8e 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs @@ -8605,6 +8605,14 @@ namespace Microsoft.SqlTools.ServiceLayer } } + public static string ActualCpu + { + get + { + return Keys.GetString(Keys.ActualCpu); + } + } + public static string EstimatedIO { get @@ -13429,6 +13437,9 @@ namespace Microsoft.SqlTools.ServiceLayer public const string EstimatedCpu = "EstimatedCpu"; + public const string ActualCpu = "ActualCpu"; + + public const string EstimatedIO = "EstimatedIO"; diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx index 4ec1a98e..c2dbeef8 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx @@ -4704,6 +4704,10 @@ The Query Processor estimates that implementing the following index could improv Estimated CPU Cost + + Actual CPU Cost + + Estimated IO Cost diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings index 9428db7e..84a8abd3 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings @@ -2258,6 +2258,7 @@ EstimatedRows = Estimated Rows ActualExecutions = Actual Executions EstimatedExecutions = Estimated Executions EstimatedCpu = Estimated CPU Cost +ActualCpu = Actual CPU Cost EstimatedIO = Estimated IO Cost 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 a60cc386..9ef56950 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf @@ -6494,6 +6494,11 @@ The Query Processor estimates that implementing the following index could improv The connection could not be found + + Actual CPU Cost + Actual CPU Cost + + \ No newline at end of file