Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Query Plan to results pane #18124

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions localization/xliff/vscode-mssql.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,9 @@
<trans-unit id="mssql.enableSqlAuthenticationProvider">
<source xml:lang="en">Enables use of the Sql Authentication Provider for &apos;Microsoft Entra Id Interactive&apos; authentication mode when user selects &apos;AzureMFA&apos; authentication. This enables Server-side resource endpoint integration when fetching access tokens. This option is only supported for &apos;MSAL&apos; Authentication Library. Please restart Visual Studio Code after changing this option.</source>
</trans-unit>
<trans-unit id="mssql.showExecutionPlanInResults">
<source xml:lang="en">Estimated Plan</source>
</trans-unit>
<trans-unit id="mssql.runCurrentStatement">
<source xml:lang="en">Execute Current Statement</source>
</trans-unit>
Expand Down
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,11 @@
"command": "mssql.changeDatabase",
"when": "editorLangId == sql",
"group": "navigation@4"
},
{
"command": "mssql.showExecutionPlanInResults",
"when": "editorLangId == sql",
"group": "navigation@4"
}
],
"editor/context": [
Expand Down Expand Up @@ -799,6 +804,15 @@
"command": "mssql.userFeedback",
"title": "%mssql.userFeedback%",
"category": "MS SQL"
},
{
"command": "mssql.showExecutionPlanInResults",
"title": "%mssql.showExecutionPlanInResults%",
"category": "MS SQL",
"icon": {
"dark": "media/executionPlan_dark.svg",
"light": "media/executionPlan_light.svg"
}
}
],
"keybindings": [
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"mssql.addAadAccount":"Add Microsoft Entra Account",
"mssql.removeAadAccount":"Remove Microsoft Entra Account",
"mssql.clearAzureAccountTokenCache":"Clear Microsoft Entra account token cache",
"mssql.showExecutionPlanInResults":"Estimated Plan",
"mssql.rebuildIntelliSenseCache":"Refresh IntelliSense Cache",
"mssql.logDebugInfo":"[Optional] Log debug output to the VS Code console (Help -> Toggle Developer Tools)",
"mssql.maxRecentConnections":"The maximum number of recently used connections to store in the connection list.",
Expand Down
1 change: 1 addition & 0 deletions src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const cmdAzureSignInToCloud = "azure-account.loginToCloud";
export const cmdAadRemoveAccount = "mssql.removeAadAccount";
export const cmdAadAddAccount = "mssql.addAadAccount";
export const cmdClearAzureTokenCache = "mssql.clearAzureAccountTokenCache";
export const cmdShowExecutionPlanInResults = "mssql.showExecutionPlanInResults";
export const cmdNewTable = "mssql.newTable";
export const cmdEditTable = "mssql.editTable";
export const cmdEditConnection = "mssql.editConnection";
Expand Down
28 changes: 28 additions & 0 deletions src/controllers/mainController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import { QueryResultWebviewController } from "../queryResult/queryResultWebViewC
import { MssqlProtocolHandler } from "../mssqlProtocolHandler";
import { isIConnectionInfo } from "../utils/utils";
import { UserSurvey } from "../nps/userSurvey";
import { ExecutionPlanOptions } from "../models/contracts/queryExecute";

/**
* The main controller class that initializes the extension
Expand All @@ -81,6 +82,10 @@ export default class MainController implements vscode.Disposable {
private _queryHistoryProvider: QueryHistoryProvider;
private _scriptingService: ScriptingService;
private _queryHistoryRegistered: boolean = false;
private _executionPlanOptions: ExecutionPlanOptions = {
includeEstimatedExecutionPlanXml: false,
includeActualExecutionPlanXml: false,
};
public sqlTasksService: SqlTasksService;
public dacFxService: DacFxService;
public schemaCompareService: SchemaCompareService;
Expand Down Expand Up @@ -186,6 +191,8 @@ export default class MainController implements vscode.Disposable {
this.registerCommand(Constants.cmdRunQuery);
this._event.on(Constants.cmdRunQuery, () => {
UserSurvey.getInstance().promptUserForNPSFeedback();
this._executionPlanOptions.includeEstimatedExecutionPlanXml =
false;
this.onRunQuery();
});
this.registerCommand(Constants.cmdManageConnectionProfiles);
Expand Down Expand Up @@ -255,6 +262,15 @@ export default class MainController implements vscode.Disposable {
this._event.on(Constants.cmdClearAzureTokenCache, () =>
this.onClearAzureTokenCache(),
);
this.registerCommand(Constants.cmdShowExecutionPlanInResults);
this._event.on(
Constants.cmdShowExecutionPlanInResults,
async () => {
this._executionPlanOptions.includeEstimatedExecutionPlanXml =
true;
this.onRunQuery();
},
);
this.initializeObjectExplorer();

this.registerCommandWithArgs(
Expand Down Expand Up @@ -335,6 +351,13 @@ export default class MainController implements vscode.Disposable {
SqlToolsServerClient.instance,
);

this._queryResultWebviewController.setExecutionPlanService(
this.executionPlanService,
);
this._queryResultWebviewController.setUntitledDocumentService(
this._untitledSqlDocumentService,
);

const providerInstance = new this.ExecutionPlanCustomEditorProvider(
this._context,
this.executionPlanService,
Expand Down Expand Up @@ -438,6 +461,7 @@ export default class MainController implements vscode.Disposable {
uri,
undefined,
title,
{},
queryPromise,
);
await queryPromise;
Expand Down Expand Up @@ -509,6 +533,8 @@ export default class MainController implements vscode.Disposable {
// Init Query Results Webview Controller
this._queryResultWebviewController = new QueryResultWebviewController(
this._context,
this.executionPlanService,
this.untitledSqlDocumentService,
);

// Init content provider for results pane
Expand Down Expand Up @@ -1522,11 +1548,13 @@ export default class MainController implements vscode.Disposable {
if (editor.document.getText(selectionToTrim).trim().length === 0) {
return;
}

await self._outputContentProvider.runQuery(
self._statusview,
uri,
querySelection,
title,
self._executionPlanOptions,
);
} catch (err) {
console.warn(`Unexpected error running query : ${err}`);
Expand Down
3 changes: 3 additions & 0 deletions src/controllers/queryRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
QueryExecutionOptionsParams,
QueryExecutionOptions,
DbCellValue,
ExecutionPlanOptions,
} from "../models/contracts/queryExecute";
import {
QueryDisposeParams,
Expand Down Expand Up @@ -197,12 +198,14 @@ export default class QueryRunner {
// Pulls the query text from the current document/selection and initiates the query
public async runQuery(
selection: ISelectionData,
executionPlanOptions?: ExecutionPlanOptions,
promise?: Deferred<boolean>,
): Promise<void> {
await this.doRunQuery(selection, async (onSuccess, onError) => {
// Put together the request
let queryDetails: QueryExecuteParams = {
ownerUri: this._ownerUri,
executionPlanOptions: executionPlanOptions,
querySelection: selection,
};

Expand Down
6 changes: 6 additions & 0 deletions src/models/contracts/queryExecute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export namespace QueryExecuteStatementRequest {

export class QueryExecuteParams {
ownerUri: string;
executionPlanOptions?: ExecutionPlanOptions;
querySelection: ISelectionData;
}

Expand All @@ -115,6 +116,11 @@ export class QueryExecuteStatementParams {

export class QueryExecuteResult {}

export class ExecutionPlanOptions {
includeActualExecutionPlanXml?: boolean;
includeEstimatedExecutionPlanXml?: boolean;
}

// ------------------------------- < Query Results Request > ------------------------------------
export namespace QueryExecuteSubsetRequest {
export const type = new RequestType<
Expand Down
20 changes: 17 additions & 3 deletions src/models/sqlOutputContentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import VscodeWrapper from "./../controllers/vscodeWrapper";
import { ISelectionData, ISlickRange } from "./interfaces";
import { WebviewPanelController } from "../controllers/webviewController";
import { IServerProxy, Deferred } from "../protocol";
import { ResultSetSubset, ResultSetSummary } from "./contracts/queryExecute";
import {
ExecutionPlanOptions,
ResultSetSubset,
ResultSetSummary,
} from "./contracts/queryExecute";
import { sendActionEvent } from "../telemetry/telemetry";
import { QueryResultWebviewController } from "../queryResult/queryResultWebViewController";
import { QueryResultPaneTabs } from "../sharedInterfaces/queryResult";
Expand Down Expand Up @@ -163,6 +167,7 @@ export class SqlOutputContentProvider {
uri: string,
selection: ISelectionData,
title: string,
executionPlanOptions?: any,
laurennat marked this conversation as resolved.
Show resolved Hide resolved
promise?: Deferred<boolean>,
): Promise<void> {
// execute the query with a query runner
Expand All @@ -178,9 +183,14 @@ export class SqlOutputContentProvider {
this._panels.get(uri).revealToForeground(uri);
}
}
await queryRunner.runQuery(selection, promise);
await queryRunner.runQuery(
selection,
executionPlanOptions as ExecutionPlanOptions,
laurennat marked this conversation as resolved.
Show resolved Hide resolved
promise,
);
}
},
executionPlanOptions,
);
}

Expand Down Expand Up @@ -219,6 +229,7 @@ export class SqlOutputContentProvider {
uri: string,
title: string,
queryCallback: any,
executionPlanOptions?: any,
): Promise<void> {
let queryRunner = await this.createQueryRunner(
statusView ? statusView : this._statusView,
Expand All @@ -239,7 +250,10 @@ export class SqlOutputContentProvider {
await this.createWebviewController(uri, title, queryRunner);
}
} else {
this._queryResultWebviewController.addQueryResultState(uri);
this._queryResultWebviewController.addQueryResultState(
uri,
executionPlanOptions?.includeEstimatedExecutionPlanXml ?? false,
laurennat marked this conversation as resolved.
Show resolved Hide resolved
);
}
if (queryRunner) {
queryCallback(queryRunner);
Expand Down
Loading
Loading