mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-23 01:25:42 -05:00
Adding ExecutionPlanService to ADS (#1422)
* Adding ExecutionPlanService to ADS * Changing name to execution plan service * Renaming file * Fixing some PR comments * Renaming class * Changing api name to queryexecutionplan
This commit is contained in:
@@ -166,6 +166,9 @@ namespace Microsoft.SqlTools.ServiceLayer
|
||||
InitializeHostedServices(serviceProvider, serviceHost);
|
||||
serviceHost.ServiceProvider = serviceProvider;
|
||||
|
||||
ShowPlan.ExecutionPlanService.Instance.InitializeService(serviceHost);
|
||||
serviceProvider.RegisterSingleService(ShowPlan.ExecutionPlanService.Instance);
|
||||
|
||||
serviceHost.InitializeRequestHandlers();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ShowPlan
|
||||
/// <summary>
|
||||
/// Graph file that used to generate ExecutionPlanGraph
|
||||
/// </summary>
|
||||
public ExecutionPlanGraphFile GraphFile { get; set; }
|
||||
public ExecutionPlanGraphInfo GraphFile { get; set; }
|
||||
/// <summary>
|
||||
/// Index recommendations given by show plan to improve query performance
|
||||
/// </summary>
|
||||
@@ -146,7 +146,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ShowPlan
|
||||
public string QueryWithDescription { get; set; }
|
||||
}
|
||||
|
||||
public class ExecutionPlanGraphFile
|
||||
public class ExecutionPlanGraphInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// File contents
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.ShowPlan
|
||||
{
|
||||
public class GetExecutionPlanParams
|
||||
{
|
||||
public ExecutionPlanGraphInfo GraphInfo { get; set; }
|
||||
}
|
||||
|
||||
public class GetExecutionPlanResult
|
||||
{
|
||||
public List<ExecutionPlanGraph> Graphs { get; set; }
|
||||
}
|
||||
|
||||
public class GetExecutionPlanRequest
|
||||
{
|
||||
public static readonly
|
||||
RequestType<GetExecutionPlanParams, GetExecutionPlanResult> Type =
|
||||
RequestType<GetExecutionPlanParams, GetExecutionPlanResult>.Create("queryexecutionplan/getexecutionplan");
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.Hosting.Protocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting;
|
||||
|
||||
@@ -12,23 +13,23 @@ namespace Microsoft.SqlTools.ServiceLayer.ShowPlan
|
||||
/// <summary>
|
||||
/// Main class for Migration Service functionality
|
||||
/// </summary>
|
||||
public sealed class ShowPlanService : IDisposable
|
||||
public sealed class ExecutionPlanService : IDisposable
|
||||
{
|
||||
private static readonly Lazy<ShowPlanService> instance = new Lazy<ShowPlanService>(() => new ShowPlanService());
|
||||
private static readonly Lazy<ExecutionPlanService> instance = new Lazy<ExecutionPlanService>(() => new ExecutionPlanService());
|
||||
|
||||
private bool disposed;
|
||||
|
||||
/// <summary>
|
||||
/// Construct a new MigrationService instance with default parameters
|
||||
/// </summary>
|
||||
public ShowPlanService()
|
||||
public ExecutionPlanService()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the singleton instance object
|
||||
/// </summary>
|
||||
public static ShowPlanService Instance
|
||||
public static ExecutionPlanService Instance
|
||||
{
|
||||
get { return instance.Value; }
|
||||
}
|
||||
@@ -49,6 +50,23 @@ namespace Microsoft.SqlTools.ServiceLayer.ShowPlan
|
||||
public void InitializeService(ServiceHost serviceHost)
|
||||
{
|
||||
this.ServiceHost = serviceHost;
|
||||
this.ServiceHost.SetRequestHandler(GetExecutionPlanRequest.Type, HandleGetExecutionPlan);
|
||||
}
|
||||
|
||||
private async Task HandleGetExecutionPlan(GetExecutionPlanParams requestParams, RequestContext<GetExecutionPlanResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
var plans = ShowPlanGraphUtils.CreateShowPlanGraph(requestParams.GraphInfo.GraphFileContent, "");
|
||||
await requestContext.SendResult(new GetExecutionPlanResult
|
||||
{
|
||||
Graphs = plans
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -22,7 +22,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ShowPlan
|
||||
{
|
||||
Root = ConvertShowPlanTreeToExecutionPlanTree(g.Root),
|
||||
Query = g.Statement,
|
||||
GraphFile = new ExecutionPlanGraphFile
|
||||
GraphFile = new ExecutionPlanGraphInfo
|
||||
{
|
||||
GraphFileContent = xml,
|
||||
GraphFileType = "xml"
|
||||
|
||||
Reference in New Issue
Block a user