MSDN Documentation

Current Location: MSDN > Documentation > SQL Server > Features > Intelligent Query Processing > Auto-Plan Correction

SQL Server Auto-Plan Correction

SQL Server's Auto-Plan Correction feature is a powerful component of Intelligent Query Processing (IQP) designed to automatically identify and mitigate performance regressions caused by suboptimal query execution plans.

Auto-Plan Correction proactively addresses query plan degradation, ensuring consistent application performance without manual intervention.

What is Query Plan Degradation?

Over time, the performance of a query can degrade. This can happen due to various factors such as changes in data distribution, increased data volume, modifications to database schema, or server configuration changes. When these factors affect the statistics used by the query optimizer, it might generate an inefficient execution plan, leading to slower query execution.

How Auto-Plan Correction Works

When enabled, Auto-Plan Correction monitors query execution. If it detects that a query's performance has significantly worsened compared to its historical performance, it can trigger the following actions:

Benefits of Auto-Plan Correction

Enabling and Configuring Auto-Plan Correction

Auto-Plan Correction is enabled at the database level. You can manage this feature using T-SQL commands.

Enabling Auto-Plan Correction:

To enable Auto-Plan Correction for a specific database, use the following command:

ALTER DATABASE CURRENT SET AUTOMATIC_TUNING (FORCE_LAST_GOOD_PLAN = ON);

Disabling Auto-Plan Correction:

To disable Auto-Plan Correction:

ALTER DATABASE CURRENT SET AUTOMATIC_TUNING (FORCE_LAST_GOOD_PLAN = OFF);

Checking the Status:

You can check the current status of automatic tuning features:

SELECT DATABASE_NAME,
       FORCE_LAST_GOOD_PLAN_STATUS,
       AUTO_EXECUTE_SCALESTATS_STATUS,
       AUTO_CREATE_INDEX_STATUS
FROM sys.dm_db_tuning_options
WHERE DATABASE_ID = DB_ID();

Considerations and Best Practices