Select calling it from my C# program, the parameters are passed in via the SqlCommand.Parameters property.įor the purposes of this discussion, you can assume that the parameters never change so we can rule out sub-optimal parameter smelling as the cause. When running the test from Query Analyzer, I prepend the following lines: declare int UPDATE: I've been asked to post the query. Sorry for the entry-level question but I can't really make heads or tails of this.
![option recompile option recompile](https://i.ytimg.com/vi/gclIG2QpYRM/maxresdefault.jpg)
Is it highly unusual to have a query that requires a recompilation hint on every single call? So why is it then, that subsequent queries that omit the OPTION (RECOMPILE) are so slow? Shouldn't the subsequent queries be making use of the lookup strategy that was computed on the previous call which included the recompilation hint? It apparently creates a new lookup strategy for the query. My understanding from the posts is that OPTION (RECOMPILE) is an expensive operation. I'm fairly comfortable with writing SQL but have never used an OPTION command in a query before and was unfamiliar with the whole concept of plan caches until scanning the posts on this forum. The query is always called with the same parameters. Calling (or not calling) DBCC FREEPROCCACHE or DBCC dropcleanbuffers makes no difference Query results are always returned instantaneously with OPTION (RECOMPILE) and greater than five minutes without it.
![option recompile option recompile](https://img.itworkman.com/images/20211225/2019040209501212.png)
![option recompile option recompile](https://community.intel.com/cipcp26785/attachments/cipcp26785/quartus-prime-software/22524/1/1.jpg)
This is the case when the query is executed from Query Analyzer or from my C# program via SqlCommand.ExecuteReader().
![option recompile option recompile](https://images2015.cnblogs.com/blog/380271/201701/380271-20170109195803822-1313890224.png)
I encountered an odd situation where appending OPTION (RECOMPILE) to my query causes it to run in half a second, while omitting it causes the query to take well over five minutes.