sys.query_store_plan_forcing_locations(Transact-SQL)

适用于: SQL Server 2025 (17.x) Azure SQL 数据库

包含使用sp_query_store_force_plan强制执行的查询存储计划信息。 利用这些信息确定哪些查询被强制计划到数据库的读写副本(主副本)和一个或多个只读副本上。

列名称 数据类型 描述
plan_forcing_location_id bigint 此计划强制位置的系统分配 ID。
query_id bigint sys.query_store_query中的引用query_id
plan_id bigint sys.query_store_plan中的引用plan_id
replica_group_id bigint 从 sp_query_store_force_plan (Transact-SQL)force_plan_scope参数。 sys.query_store_replicas中的引用replica_group_id
timestamp datetime 计划强制操作应用的UTC日期和时间。
plan_forcing_type int 计划强制类型。

0 = NONE
1 = MANUAL
2 = AUTO
plan_forcing_type_desc nvarchar(60) 文本说明 plan_forcing_type。

NONE:没有强制计划
MANUAL:用户强制计划
AUTO:计划由自动调音强制

权限

需要 VIEW DATABASE STATE 权限。

SQL Server 2022 及更高版本的权限

需要在数据库上具有VIEW DATABASE PERFORMANCE STATE权限。

示例

使用sys.query_store_plan_forcing_locations,与sys.query_store_replicas连接,检索被强制执行的前20 查询存储计划。

SELECT TOP (20)
    pfl.query_id,
    pfl.plan_id,
    CASE qsr.replica_group_id
        WHEN 1 THEN 'PRIMARY'
        WHEN 2 THEN 'SECONDARY'
        WHEN 3 THEN 'GEO SECONDARY'
        WHEN 4 THEN 'GEO HA SECONDARY'
        ELSE CONCAT('REPLICA_', qsr.replica_group_id)
    END AS replica_type,
    pfl.[timestamp],
    pfl.plan_forcing_type_desc
FROM sys.query_store_plan_forcing_locations AS pfl
INNER JOIN sys.query_store_replicas AS qsr
    ON qsr.replica_group_id = pfl.replica_group_id
ORDER BY pfl.[timestamp] DESC;