Josh Darnell does some sleuthing:
With a big gap between CPU and elapsed time, it’s often worthwhile to check wait statistics. If the query was running, but not using CPU, it seems reasonable that it was waiting on something. Normally, with on-prem SQL Server, you’d have to check
sys.dm_os_wait_stats
, and take a diff of the cumulative values before and after.However, thanks to (relatively) recent enhancements to execution plans (which keep getting better and better!), we can see a subset of what resources the query waited on right in the plan.
Looking at the plan from my Azure query, here’s what I see:
<Wait WaitType="SOS_SCHEDULER_YIELD" WaitTimeMs="5733" WaitCount="323" />
<Wait WaitType="RESOURCE_GOVERNOR_IDLE" WaitTimeMs="5545" WaitCount="430" />Notice that there were 5.5 seconds of
RESOURCE_GOVERNOR_IDLE
waits during this query. That explains the 5 second gap in CPU and elapsed time. But what does it mean?
Click through to learn more about this in the context of Azure SQL Database.