

I’ll give some pros and cons for each method and explain what’s useful and what’s worth avoiding. This post runs through common options you have to nudge (or whack) SQL Server into generating a fresh execution plan.
#Sql server option recompile free#
(Not sure what parameter sniffing is? Learn from this blog post or this 50 minute free video.) You must decide: what hint or command do you use, and where do you put it? What trade-offs are you making when it comes to being able to performance tune your SQL Server in the future?

#Sql server option recompile password#

If the hint was removed in the procedure we would end up with something like below:-Īnother way to achieve RECOMPILES without actually modifying the procedure would be to call the hint at run time as shown below Result of querying the plan cache can be seen below:. Since we need to recompile it every time the procedure executed there is no sense wasting memory on it.

When used this way we see that the Execution plan is discarded as soon as the query finishes execution. This hint allows us to recompile the entire stored procedure (not just bits and pieces of it) each time it is executed. Here is the question that was being asked. To allow us to do this we have a few option. In such cases it is better to RECOMPILE the procedure so that it always takes into account the current state and comes up with a new plan each time. A simple example would be when the number of rows in the table have changed significantly. But like all things in life situations change and the plan that was working before might not be the best anymore. Because a stored procedure is something that gets executed frequently it makes sense to reuse the plan over and over again. Ideally the plan takes into account the current situations and arrives at what it thinks would get the job done in the quickest way with the least resources consumed. Stored procedures can be expensive to run so SQL Server database engine takes a moment when running the procedure the first time to come up with a plan. If you are not sure about how recompile works here is a quick primer. An interesting problem was posted on #SQLHelp the other day about using the QueryHint OPTION(RECOMPILE).
