mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-17 02:51:45 -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);
|
InitializeHostedServices(serviceProvider, serviceHost);
|
||||||
serviceHost.ServiceProvider = serviceProvider;
|
serviceHost.ServiceProvider = serviceProvider;
|
||||||
|
|
||||||
|
ShowPlan.ExecutionPlanService.Instance.InitializeService(serviceHost);
|
||||||
|
serviceProvider.RegisterSingleService(ShowPlan.ExecutionPlanService.Instance);
|
||||||
|
|
||||||
serviceHost.InitializeRequestHandlers();
|
serviceHost.InitializeRequestHandlers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ShowPlan
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Graph file that used to generate ExecutionPlanGraph
|
/// Graph file that used to generate ExecutionPlanGraph
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ExecutionPlanGraphFile GraphFile { get; set; }
|
public ExecutionPlanGraphInfo GraphFile { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Index recommendations given by show plan to improve query performance
|
/// Index recommendations given by show plan to improve query performance
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -146,7 +146,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ShowPlan
|
|||||||
public string QueryWithDescription { get; set; }
|
public string QueryWithDescription { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ExecutionPlanGraphFile
|
public class ExecutionPlanGraphInfo
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// File contents
|
/// 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;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Microsoft.SqlTools.Hosting.Protocol;
|
using Microsoft.SqlTools.Hosting.Protocol;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Hosting;
|
using Microsoft.SqlTools.ServiceLayer.Hosting;
|
||||||
|
|
||||||
@@ -12,23 +13,23 @@ namespace Microsoft.SqlTools.ServiceLayer.ShowPlan
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Main class for Migration Service functionality
|
/// Main class for Migration Service functionality
|
||||||
/// </summary>
|
/// </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;
|
private bool disposed;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Construct a new MigrationService instance with default parameters
|
/// Construct a new MigrationService instance with default parameters
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ShowPlanService()
|
public ExecutionPlanService()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the singleton instance object
|
/// Gets the singleton instance object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static ShowPlanService Instance
|
public static ExecutionPlanService Instance
|
||||||
{
|
{
|
||||||
get { return instance.Value; }
|
get { return instance.Value; }
|
||||||
}
|
}
|
||||||
@@ -49,6 +50,23 @@ namespace Microsoft.SqlTools.ServiceLayer.ShowPlan
|
|||||||
public void InitializeService(ServiceHost serviceHost)
|
public void InitializeService(ServiceHost serviceHost)
|
||||||
{
|
{
|
||||||
this.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>
|
/// <summary>
|
||||||
@@ -22,7 +22,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ShowPlan
|
|||||||
{
|
{
|
||||||
Root = ConvertShowPlanTreeToExecutionPlanTree(g.Root),
|
Root = ConvertShowPlanTreeToExecutionPlanTree(g.Root),
|
||||||
Query = g.Statement,
|
Query = g.Statement,
|
||||||
GraphFile = new ExecutionPlanGraphFile
|
GraphFile = new ExecutionPlanGraphInfo
|
||||||
{
|
{
|
||||||
GraphFileContent = xml,
|
GraphFileContent = xml,
|
||||||
GraphFileType = "xml"
|
GraphFileType = "xml"
|
||||||
|
|||||||
Reference in New Issue
Block a user