I finally found the time to work through the questions from the 24 Hours of PASS session that I did. Thanks to everyone that attended the event
Q1: Can you filter execution plans for sort warnings?
No. The sort and hash warnings don’t appear in the execution plan. You’d have to trace for the hash and sort warning events and correlate that with either batch/statement started and completed events or with the run-time plan events.
Q2: To get the query executions can you just add the statement completed or batch completed events?
The Statement Completed and Batch completed events have durations and can be filtered on that duration. The problem however is that the execution plan events (eg showplan all, showplan xml, statistics profile, statistics xml) have no duration column. Hence the execution plan events can’t be filtered on duration even though the statement_completed and batch_completed events can.
Q3: If you run a Profiler trace and all the plans are being pulled from cache will that mean that no ShowPlan event data will be shown in the trace?
Depends which event is being traced. There are events for query compile (showplan all for query compile and showplan xml for query compile) that only fire when the query compiles, so those will not fire if the plan is being pulled from cache. The other execution plan events are all fired each time the query executes.
Q4: Why can you sometimes get nulls or blank strings for the query plan from sys.dm_exec_query_plan
From Books Online:
Under the following conditions, no Showplan output is returned in the query_plan column of the returned table for sys.dm_exec_query_plan:
- If the query plan that is specified by using plan_handle has been evicted from the plan cache, the query_plan column of the returned table is null.
- Some Transact-SQL statements are not cached, such as bulk operation statements or statements containing string literals larger than 8 KB in size. XML Showplans for such statements cannot be retrieved by using sys.dm_exec_query_plan unless the batch is currently executing because they do not exist in the cache.
Q5: Do the execution plans from the DMVs contain execution information?
No. The plans extracted from cache contain compile-time information only.