snippetsqlMinor
Is there a reliable way to determine how long it took the optimizer to generate a query plan?
Viewed 0 times
tookthereliablequerywaylongoptimizerplangeneratedetermine
Problem
I'm not sure where I'd start, but is there a way to see how long it took the optimizer to generate a query plan for a query? Is it stored in any of the DMVs or something that's part of one of the statistics? Or can I calculate it somehow if I include live statistics or the actual execution plan? Maybe in the query store?
Solution
There are many ways :
SQL Server parse and compile time:
CPU time = xx ms, elapsed time = xx ms.
There are many other ways like profiler, server side trace or XEvents - but they are expensive and might have negative perf impact on your sql server.
You can use sp_BlitzCache to find out Query Compilation Timeout from plan cache.
- If you can run the query
- you can use
set statistics time onwhich will give you:
SQL Server parse and compile time:
CPU time = xx ms, elapsed time = xx ms.
- If you cant run the query, then mine the plan cache to check for query compile time along with many other significant insights.
There are many other ways like profiler, server side trace or XEvents - but they are expensive and might have negative perf impact on your sql server.
You can use sp_BlitzCache to find out Query Compilation Timeout from plan cache.
Context
StackExchange Database Administrators Q#252463, answer score: 8
Revisions (0)
No revisions yet.