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:
Aasim Khan
2022-01-28 11:35:48 -08:00
committed by GitHub
parent a98c266791
commit 92a7248455
13 changed files with 2167 additions and 59 deletions

View File

@@ -30,7 +30,11 @@
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<ItemGroup>
<Content Remove=".\ShowPlan\TestExecution.xml" />
<EmbeddedResource Include=".\ShowPlan\TestExecutionPlan.xml" />
<Content Remove=".\ShowPlan\TestExecution.xml" />
<EmbeddedResource Include=".\ShowPlan\TestExecutionPlan.xml" />
</ItemGroup>
</Project>
<ItemGroup>
<Content Remove=".\ShowPlan\TestExecutionPlanRecommendations.xml" />
<EmbeddedResource Include=".\ShowPlan\TestExecutionPlanRecommendations.xml" />
</ItemGroup>
</Project>

View File

@@ -4,6 +4,7 @@ using System;
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using NUnit.Framework;
@@ -16,20 +17,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ShowPlan
{
private string queryPlanFileText;
[SetUp]
public void LoadQueryPlanBeforeEachTest()
{
Assembly assembly = Assembly.GetAssembly(typeof(ShowPlanXMLTests));
Stream scriptStream = assembly.GetManifestResourceStream(assembly.GetName().Name + ".ShowPlan.TestExecutionPlan.xml");
StreamReader reader = new StreamReader(scriptStream);
queryPlanFileText = reader.ReadToEnd();
}
[Test]
public void ParseXMLFileReturnsValidShowPlanGraph()
{
var showPlanGraphs = ShowPlanGraphUtils.CreateShowPlanGraph(queryPlanFileText);
ReadFile(".ShowPlan.TestExecutionPlan.xml");
var showPlanGraphs = ShowPlanGraphUtils.CreateShowPlanGraph(queryPlanFileText, "testFile.sql");
Assert.AreEqual(1, showPlanGraphs.Count, "exactly one show plan graph should be returned");
Assert.NotNull(showPlanGraphs[0], "graph should not be null");
Assert.NotNull(showPlanGraphs[0].Root, "graph should have a root");
@@ -38,8 +30,9 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ShowPlan
[Test]
public void ParsingNestedProperties()
{
ReadFile(".ShowPlan.TestExecutionPlan.xml");
string[] commonNestedPropertiesNames = { "MemoryGrantInfo", "OptimizerHardwareDependentProperties" };
var showPlanGraphs = ShowPlanGraphUtils.CreateShowPlanGraph(queryPlanFileText);
var showPlanGraphs = ShowPlanGraphUtils.CreateShowPlanGraph(queryPlanFileText, "testFile.sql");
ExecutionPlanNode rootNode = showPlanGraphs[0].Root;
rootNode.Properties.ForEach(p =>
{
@@ -49,5 +42,24 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ShowPlan
}
});
}
[Test]
public void ParseXMLFileWithRecommendations()
{
//The first graph in this execution plan has 3 recommendations
ReadFile(".ShowPlan.TestExecutionPlanRecommendations.xml");
string[] commonNestedPropertiesNames = { "MemoryGrantInfo", "OptimizerHardwareDependentProperties" };
var showPlanGraphs = ShowPlanGraphUtils.CreateShowPlanGraph(queryPlanFileText, "testFile.sql");
List<ExecutionPlanRecommendation> rootNode = showPlanGraphs[0].Recommendations;
Assert.AreEqual(3, rootNode.Count, "3 recommendations should be returned by the showplan parser");
}
private void ReadFile(string fileName)
{
Assembly assembly = Assembly.GetAssembly(typeof(ShowPlanXMLTests));
Stream scriptStream = assembly.GetManifestResourceStream(assembly.GetName().Name + fileName);
StreamReader reader = new StreamReader(scriptStream);
queryPlanFileText = reader.ReadToEnd();
}
}
}