Live Query Statistics Don’t Replace Actual Execution Plans
I like SQL Server’s new Live Query Statistics feature a lot for testing and tuning large queries. One of my first questions was whether this could replace using actual execution plans, or if it’s useful to use both during testing.
Spoiler: Both are useful. And both can impact query performance.
Live Query Statistics Gives Insight into Plan Processing
I’m loading a bunch of rows into a partitioned heap. Here’s what the insert looks like in Live Query Statistics when run with parallelism. Note that the progress on the Sort operator remains at 0% done until the Clustered Index Scan and Compute Scalar operators feeding it are 100% complete:
Here’s what that same insert looks like when run at maxdop 1. In this case the operators are ordered differently, and the Sort Operator is able to make progress while the Clustered Index Scan is still running.
This insert runs significantly faster at MAXDOP 1, and Live Query Statistics really helps see why. The single threaded plan doesn’t have to wait — it can stream more through at once.
The single threaded plan uses teamwork, like this:[iframe src=”http://giphy.com/embed/o7BebTgj44jmw” width=”500″ height=”240″ frameBorder=”0″ webkitAllowFullScreen mozallowfullscreen allowFullScreen][/iframe]
Live Query Statistics Didn’t Tell Us About the tempdb Spill
When the query completes, Live Query Statistics tells us that everything is 100% done. It doesn’t say anything about a tempdb spill.
To see the that this tempdb spill occurred as part of the query, we need to have turned on “Actual Execution Plans”. Then we can see click over to the Execution Plans tab and see this:
Hovering over the warning on the sort operator, we can see more details about the tempdb spill:
Observation Has a Performance Cost
Getting plan details isn’t free. The amount of impact depends on what the query is doing, but there’s a stiff overhead to collecting actual execution plans and to watching live query statistics.
These tools are great for reproing problems and testing outside of production, but don’t time query performance while you’re using them– you’ll get too much skew.