獲取 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