mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-06 09:35:39 -05:00
Adding recommendations to query plan (#1373)
* Adding recommendations * Adding raw graph type in execution plan graph contracts * Fixing function name and concising string formatting * Converting localized string to a function * Using better names in contract props Formatting names in a better way * Getting rid of unnecessary getter, setters and private props * Fixing localized strings, comments and imports * Fixing some contracts * Fixing csproj formatting * Fixing var names * Fixing xml comments
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
@@ -12,14 +13,19 @@ namespace Microsoft.SqlTools.ServiceLayer.ShowPlan
|
||||
{
|
||||
public class ShowPlanGraphUtils
|
||||
{
|
||||
public static List<ExecutionPlanGraph> CreateShowPlanGraph(string xml)
|
||||
public static List<ExecutionPlanGraph> CreateShowPlanGraph(string xml, string fileName)
|
||||
{
|
||||
ShowPlanGraph.ShowPlanGraph[] graphs = ShowPlanGraph.ShowPlanGraph.ParseShowPlanXML(xml, ShowPlanGraph.ShowPlanType.Unknown);
|
||||
return graphs.Select(g => new ExecutionPlanGraph
|
||||
{
|
||||
Root = ConvertShowPlanTreeToExecutionPlanTree(g.Root),
|
||||
Query = g.Statement,
|
||||
XmlString = xml
|
||||
GraphFile = new ExecutionPlanGraphFile
|
||||
{
|
||||
GraphFileContent = xml,
|
||||
GraphFileType = "xml"
|
||||
},
|
||||
Recommendations = ParseRecommendations(g, fileName)
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
@@ -85,5 +91,36 @@ namespace Microsoft.SqlTools.ServiceLayer.ShowPlan
|
||||
}
|
||||
return propsList;
|
||||
}
|
||||
|
||||
private static List<ExecutionPlanRecommendation> ParseRecommendations(ShowPlanGraph.ShowPlanGraph g, string fileName)
|
||||
{
|
||||
return g.Description.MissingIndices.Select(mi => new ExecutionPlanRecommendation
|
||||
{
|
||||
DisplayString = mi.MissingIndexCaption,
|
||||
Query = mi.MissingIndexQueryText,
|
||||
QueryWithDescription = ParseMissingIndexQueryText(fileName, mi.MissingIndexImpact, mi.MissingIndexDatabase, mi.MissingIndexQueryText)
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates query file text for the recommendations. It has the missing index query along with some lines of description.
|
||||
/// </summary>
|
||||
/// <param name="fileName">query file name that has generated the plan</param>
|
||||
/// <param name="impact">impact of the missing query on performance</param>
|
||||
/// <param name="database">database name to create the missing index in</param>
|
||||
/// <param name="query">actual query that will be used to create the missing index</param>
|
||||
/// <returns></returns>
|
||||
private static string ParseMissingIndexQueryText(string fileName, string impact, string database, string query)
|
||||
{
|
||||
return $@"{SR.MissingIndexDetailsTitle(fileName, impact)}
|
||||
|
||||
/*
|
||||
{string.Format("USE {0}", database)}
|
||||
GO
|
||||
{string.Format("{0}", query)}
|
||||
GO
|
||||
*/
|
||||
";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user