HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Tell SQL Server a query is ad hoc and not to optimize based on it

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
sqlqueryandtelloptimizebasedservernothoc

Problem

Is there a way to run a one-off query against a production SQL Server database and tell it not to make any future judgments based on that query. E.g. Store execution plans, recommend indexes, etc.

Or perhaps I shouldn't be so concerned.

Solution

You can add the query hint OPTION (RECOMPILE).

This effectively tells SQL Server, "Give me a plan to execute this query one time, but don't save it in the plan cache".

Take a peek at Kendra Little's article on RECOMPILE hints and execution plan caching. She covers all the uses and potential effects.

RECOMPILE Hints and Execution Plan Caching

Also see:

Parameter Sniffing, Embedding, and the RECOMPILE Options

Regarding disabling the missing index feature, the only supported way to do that is to start SQL Server from the command line with the -x switch. That is not what you want, but it does set a limit on your options.

Context

StackExchange Database Administrators Q#112568, answer score: 7

Revisions (0)

No revisions yet.