Brent Ozar 4/21/2026

There’s a Bug in sys.dm_exec_query_plan_stats.

Read Original

This article by Brent Ozar details a bug in SQL Server 2019 and newer where the system function sys.dm_exec_query_plan_stats incorrectly reports CPU time and elapsed time values. When LAST_QUERY_PLAN_STATS is enabled, the function is supposed to show the last actual query plan, but the CPU and elapsed time numbers are swapped. The author provides a repro query using GENERATE_SERIES and SET STATISTICS TIME to demonstrate the discrepancy, comparing the correct values from sys.dm_exec_query_stats with the incorrect ones from the XML plan. This is a technical deep dive for SQL Server DBAs and developers.

There’s a Bug in sys.dm_exec_query_plan_stats.

Comments

No comments yet

Be the first to share your thoughts!

Browser Extension

Get instant access to AllDevBlogs from your browser

Top of the Week

No top articles yet