获取 SQL 查询计划的执行统计信息
以下查询将返回有关其持续时间,CPU 时间,物理和逻辑 io 读取的 Qeries,其计划和平均统计信息。
SELECT Txt.query_text_id, Txt.query_sql_text, Pl.plan_id,
avg_duration, avg_cpu_time,
avg_physical_io_reads, avg_logical_io_reads
FROM sys.query_store_plan AS Pl
JOIN sys.query_store_query AS Qry
ON Pl.query_id = Qry.query_id
JOIN sys.query_store_query_text AS Txt
ON Qry.query_text_id = Txt.query_text_id
JOIN sys.query_store_runtime_stats Stats
ON Pl.plan_id = Stats.plan_id