Подія
31 бер., 23 - 2 квіт., 23
Найбільший навчальний захід SQL, Fabric і Power BI. 31 березня – 2 квітня. Щоб заощадити 400 грн, скористайтеся кодом FABINSIDER.
Реєструйтеся сьогодніЦей браузер більше не підтримується.
Замініть його на Microsoft Edge, щоб користуватися перевагами найновіших функцій, оновлень безпеки та технічної підтримки.
Applies to:
SQL Server 2022 (16.x)
Azure SQL Database
Azure SQL Managed Instance
SQL database in Microsoft Fabric
Changes the configuration for the automatic plan correction (APC) component of the automatic tuning feature. The configuration options apply to a given query_id
which can be obtained from the Query Store.
These options include the ability to allow a query_id
to be allowed or skipped for APC consideration, or to configure APC to apply an additional extended, time-based plan regression check to that specific query. The configuration options are not mutually exclusive.
Transact-SQL syntax conventions
Syntax for SQL Server 2022 (16.x), Azure SQL Managed Instance:
sp_configure_automatic_tuning
[ @option = ] 'FORCE_LAST_GOOD_PLAN'
, [ @type = ] 'type'
[ , [ @type_value = ] N'type_value' ]
, [ @option_value = ] { 'ON' | 'OFF' }
Syntax for Azure SQL Database, SQL database in Microsoft Fabric:
sp_configure_automatic_tuning
[ @option = ] { 'FORCE_LAST_GOOD_PLAN' | 'FORCE_LAST_GOOD_PLAN_EXTENDED_CHECK' }
, [ @type = ] 'type'
[ , [ @type_value = ] N'type_value' ]
, [ @option_value = ] { 'ON' | 'OFF' }
Specifies the name of the configuration option to be invoked. @option is varchar(60), with no default, and can be one of these values.
Value | Description |
---|---|
FORCE_LAST_GOOD_PLAN |
Enables APC to identify execution plan choice regressions and to automatically fix the issue by forcing the last known good plan as recorded in the Query Store. See What is execution plan choice regression? |
FORCE_LAST_GOOD_PLAN_EXTENDED_CHECK |
Applies to: Azure SQL Database and SQL database in Microsoft Fabric only. Instructs APC to use an additional time-based plan regression check, which occurs five minutes after a plan change is detected. This check allows APC to avoid biasing its regression checks for queries that execute quickly. With this option, APC takes into account query executions that might run longer, or are prone to timing out because of a plan change. |
The type of object the configuration applies to. @type is varchar(60) with no default. Possible value is QUERY
.
The query ID from Query Store that the configuration should be applied to. @type_value is sysname with no defaults.
The desired state of the configuration setting. @option_value is varchar(60) with no defaults. Possible values are ON
or OFF
. For the FORCE_LAST_GOOD_PLAN
option, setting the value to OFF
causes APC to ignore a query_id
in the Query Store from being monitored by the system for query plan regressions.
0
(success) or 1
(failure).
You can also check to see which configuration options are set, by viewing the output of the sys.database_automatic_tuning_configurations catalog view. Changes to the catalog view are also written to the SQL Server error log.
Requires the ALTER DATABASE
permission.
For SQL Server 2022 (16.x) CU 4 and later versions, the behavior of the FORCE_LAST_GOOD_PLAN_EXTENDED_CHECK
configuration option can be applied to the entire SQL Server instance with global trace flag 12656. All queries eligible for Query Store capture have the additional time-based regression check logic applied.
The following example shows how to configure automatic tuning to ignore a query if it's eligible for automatic plan forcing. This example uses a value of 422
as the query_id
that was selected from the Query Store.
EXECUTE sys.sp_configure_automatic_tuning 'FORCE_LAST_GOOD_PLAN', 'QUERY', 422, 'OFF';
In this example, we can see all of the query_id
results that are part of any update cursor statements, which are forced by the APC feature.
SELECT qry.query_id,
pl.plan_forcing_type_desc,
pl.is_forced_plan,
pl.plan_id
FROM sys.query_store_plan AS pl
INNER JOIN sys.query_store_query AS qry
ON qry.query_id = pl.query_id
WHERE pl.query_plan LIKE '%StatementType="UPDATE CURSOR"%'
AND pl.is_forced_plan > 0
AND pl.plan_forcing_type = 2;
Based on the results of the previous query, the query_id
with the value of 42
is a query that should be ignored by APC. We can use the named parameter version of the syntax for sp_configure_automatic_tuning
as follows.
EXECUTE sys.sp_configure_automatic_tuning
@option = 'FORCE_LAST_GOOD_PLAN',
@type = 'QUERY',
@type_value = 42,
@option_value = 'OFF';
Check if the setting is applied.
SELECT *
FROM sys.database_automatic_tuning_configurations;
Applies to: Azure SQL Database, SQL database in Microsoft Fabric:
APC uses a time-based plan regression check, which occurs five minutes after a plan change is detected. This check allows APC to avoid biasing its regression checks for queries that execute quickly. APC takes into account query executions that might run longer, or are prone to timing out because of a plan change.
The following example shows how to configure automatic tuning to apply its extended check logic to a query if it's eligible for automatic plan forcing. This example is using a value of 442
as the query_id
that was selected from the Query Store.
EXECUTE sys.sp_configure_automatic_tuning 'FORCE_LAST_GOOD_PLAN_EXTENDED_CHECK', 'QUERY', 442, 'ON';
Подія
31 бер., 23 - 2 квіт., 23
Найбільший навчальний захід SQL, Fabric і Power BI. 31 березня – 2 квітня. Щоб заощадити 400 грн, скористайтеся кодом FABINSIDER.
Реєструйтеся сьогодні