title: "Auto Tuning" date: "11/21/2018"
When migrating from an older version of SQL Server and upgrading the database compatibility level to the latest available, a workload may be exposed to the risk of performance regression.
Starting with SQL Server 2016, all query optimizer changes are gated to the latest database compatibility level, which in combination with Query Store gives you a great level of control over the query performance in the upgrade process if the upgrade follows the recommended workflow seen below.
In SQL Server 2016, users are able to use SSMS Query Store reports to identify regressed queries that occur post-database upgrade, and manually force a specific pre-upgrade plan to be used. This maps to the last step in the recommended workflow above.
This control over upgrades was further improved with SQL Server 2017 where Automatic Tuning was introduced and allows automating the last step in the recommended workflow above. This lab allows you to see the feature in action.
The following are requirements to run this lab:
C:\Program Files\Microsoft Corporation\RMLUtils to your path variable.WideWorldImporters database is available in https://github.com/Microsoft/sql-server-samples/tree/master/samples/databases/wide-world-importers.Open the folder C:\Labs\Lab-AutoTuning\SCENARIO and double-click the file Scenario.cmd to execute it. This starts the workload. Leave it running...
Setup Performance Monitor on Windows to track SQL Statistics/Batch Requests/sec counter. Alternatively, open the file C:\Labs\Lab-AutoTuning\SCENARIO\Perfmon.htm with Internet Explorer. Note you may receive a prompt warning that Internet Explorer blocked ActiveX content. Click on Allow blocked content.
While the scenario workload is running, double-click the file Regression.cmd in the same folder to execute it. Notice the drop in the batch requests/sec counter which means a performance regression was introduced in the workload.
Open the file C:\Labs\Lab-AutoTuning\SCENARIO\recommendations.sql with SQL Server Management Studio or SQL Operations Studio, execute it and review the results:
Stop the scenario workload by pressing CTRL+C, and then choose "N" when prompted to terminate the batch.
Now let's see what happens with automatic plan correction which uses this command in SQL Server 2017:
ALTER DATABASE WideWorldImporters
SET AUTOMATIC_TUNING ( FORCE_LAST_GOOD_PLAN = ON )
Double-click the file Auto_tune.cmd in the same folder to execute it. This uses the above command to set automatic plan correct ON for WideWorldImporters, and restarts the workload file Scenario.cmd.
Repeat steps 3-5 as above, and note the following:
C:\Labs\Lab-AutoTuning\SCENARIO\recommendations.sql with SQL Server Management Studio or SQL Operations Studio, execute it and notice the state_transition_reason column value is now LastGoodPlanForced.