Quantcast
Viewing all articles
Browse latest Browse all 3160

Enabling Optimize For Ad Hoc Workloads In SQL Server

The option to enable Optimize for Ad hoc Workloads in SQL Server has quickly become one of my most recommended settings. When enabled this setting instructs SQL Server to only store a snippet of the query plan each time a query is executed for the first time . Only when that snippet of a query plan is referenced a second time will SQL Server store the entire query plan. This is very beneficial when considering the amount of space being consumed by single use query plans, especially in large scale environments.

Optimize for Ad hoc Workloads was introduced in SQL Server 2008 so if you’re working in an older environment you won’t be able to utilize this feature.

Like most things in SQL Server, there are a couple different ways you can enable (or disable) the option to Optimize for Ad hoc Workloads. This is an online server setting so this can be enabled without disrupting services and will apply to all database on the server.

The first way to go about enabling this feature is through the GUI in SQL Server Management Studio. Once you are connected to the server, simply right-click the server and select Properties as shown below.


Image may be NSFW.
Clik here to view.
Enabling Optimize For Ad Hoc Workloads In SQL Server

On the Server Properties window select the Advanced page. Under the Miscellaneous grouping you will see the option for Optimize for Ad hoc Workloads.

Simply change this value from False to True and click OK.


Image may be NSFW.
Clik here to view.
Enabling Optimize For Ad Hoc Workloads In SQL Server

As mentioned previously, this is an online setting so no need for a service restart or any downtime.

The other option for enabling this is through scripting. The following script uses the SP_CONFIGURE command to perform the same task outlined above.

SP_CONFIGURE 'Show Advanced Options', 1 GO RECONFIGURE GO SP_CONFIGURE 'optimize for ad hoc workloads', 1 GO RECONFIGURE GO

To be honest, I have yet to find a situation where enabling Optimize for Ad hoc Workloads is not beneficial, though I am sure there are scenarios out there where this may not be the case. I supposed if you have a SQL Server that is dedicated to a very specific task where queries are streamlined and do not change often then leaving this disabled may be suitable. I’m a little surprised this setting is not enabled by default but it’s such an easy setting to apply and will very likely be something you will end up applying to most, if not all, your production SQL Server environments.


Viewing all articles
Browse latest Browse all 3160

Trending Articles