Skip to content

Commit 7fd06f9

Browse files
committed
more edits
1 parent 787c356 commit 7fd06f9

1 file changed

Lines changed: 22 additions & 20 deletions

File tree

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,38 @@
11
---
2-
title: "optimize for ad hoc workloads Server Configuration Option | Microsoft Docs"
2+
title: optimize for ad hoc workloads Server Configuration Option
33
description: 'Learn about the "optimize for ad hoc workloads" option. Use it to improve SQL Server plan cache efficiency when workloads contain many single-use ad hoc batches.'
4-
ms.custom: ""
5-
ms.date: "11/17/2017"
64
ms.prod: sql
75
ms.prod_service: high-availability
86
ms.reviewer: ""
97
ms.technology: configuration
108
ms.topic: conceptual
119
helpviewer_keywords:
1210
- "optimize for ad hoc workloads option"
13-
ms.assetid: 0972e028-3a8e-454b-a186-e814a1d431f2
1411
author: markingmyname
1512
ms.author: maghan
13+
ms.custom: ""
14+
ms.date: "11/17/2017"
1615
---
16+
1717
# optimize for ad hoc workloads Server Configuration Option
18-
[!INCLUDE [SQL Server](../../includes/applies-to-version/sqlserver.md)]
19-
20-
The **optimize for ad hoc workloads** option is used to improve the efficiency of the plan cache for workloads that contain many single use ad hoc batches. When this option is set to 1, the [!INCLUDE[ssDE](../../includes/ssde-md.md)] stores a small compiled plan stub in the plan cache when a batch is compiled for the first time, instead of the full compiled plan. This helps to relieve memory pressure by not allowing the plan cache to become filled with compiled plans that are not reused.
21-
22-
The compiled plan stub allows the [!INCLUDE[ssDE](../../includes/ssde-md.md)] to recognize that this ad hoc batch has been compiled before but has only stored a compiled plan stub, so when this batch is invoked (compiled or executed) again, the [!INCLUDE[ssDE](../../includes/ssde-md.md)] compiles the batch, removes the compiled plan stub from the plan cache, and adds the full compiled plan to the plan cache.
23-
24-
The compiled plan stub is one of the cacheobjtypes displayed by the sys.dm_exec_cached_plans catalog view. It has a unique sql handle and plan handle. The compiled plan stub does not have an execution plan associated with it and querying for the plan handle will not return an XML Showplan.
25-
26-
[Trace flag 8032](../../t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql.md) reverts the cache limit parameters to the [!INCLUDE[ssVersion2005](../../includes/ssversion2005-md.md)] RTM setting which in general allows caches to be larger. Use this setting when frequently reused cache entries do not fit into the cache and when the optimize for ad hoc workloads Server Configuration Option has failed to resolve the problem with plan cache.
27-
18+
19+
[!INCLUDE [SQL Server Azure SQL Database](../../includes/applies-to-version/sql-asdb-asdbmi-pdw.md)]
20+
21+
The **optimize for ad hoc workloads** option is used to improve the efficiency of the plan cache for workloads that contain many single use ad hoc batches. When this option is set to 1, the
22+
23+
[!INCLUDE[ssDE](../../includes/ssde-md.md)] stores a small compiled plan stub in the plan cache when a batch is compiled for the first time, instead of the full compiled plan. This helps to relieve memory pressure by not allowing the plan cache to become filled with compiled plans that are not reused.
24+
25+
The compiled plan stub allows the [!INCLUDE[ssDE](../../includes/ssde-md.md)] to recognize that this ad hoc batch has been compiled before but has only stored a compiled plan stub, so when this batch is invoked (compiled or executed) again, the [!INCLUDE[ssDE](../../includes/ssde-md.md)] compiles the batch, removes the compiled plan stub from the plan cache, and adds the full compiled plan to the plan cache.
26+
27+
The compiled plan stub is one of the cacheobjtypes displayed by the sys.dm_exec_cached_plans catalog view. It has a unique sql handle and plan handle. The compiled plan stub does not have an execution plan associated with it and querying for the plan handle will not return an XML Showplan.
28+
29+
[Trace flag 8032](../../t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql.md) reverts the cache limit parameters to the [!INCLUDE[ssVersion2005](../../includes/ssversion2005-md.md)] RTM setting which in general allows caches to be larger. Use this setting when frequently reused cache entries do not fit into the cache and when the optimize for ad hoc workloads Server Configuration Option has failed to resolve the problem with plan cache.
30+
2831
> [!WARNING]
29-
> Trace flag 8032 can cause poor performance if large caches make less memory available for other memory consumers, such as the buffer pool.
32+
> Trace flag 8032 can cause poor performance if large caches make less memory available for other memory consumers, such as the buffer pool.
3033
3134
## Recommendations
35+
3236
Avoid having a large number of single-use plans in the plan cache. A common cause of this problem is when the data types of query parameters is not consistently defined. This particularly applies to the length of strings but can apply to any data type that has a maxlength, a precision, or a scale. For example, if a parameter named @Greeting is passed as an nvarchar(10) on one call and an nvarchar(20) on the next call, separate plans are created for each parameter size. If a query has several parameters and they are not consistently defined when called, a large number of query plans could exist for each query. Plans could exist for each combination of query parameter data types and lengths that have been used.
3337

3438
If the number of single-use plans take a significant portion of [!INCLUDE[ssDEnoversion](../../includes/ssdenoversion-md.md)] memory in an OLTP server, and these plans are Ad-hoc plans, use this server option to decrease memory usage with these objects.
@@ -48,8 +52,6 @@ GROUP BY objtype, cacheobjtype;
4852
> Setting the **optimize for ad hoc workloads** to 1 affects only new plans; plans that are already in the plan cache are unaffected.
4953
> To affect already cached query plans immediately, the plan cache needs to be cleared using [ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE](../../t-sql/statements/alter-database-scoped-configuration-transact-sql.md), or [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] has to restart.
5054
51-
## See Also
52-
[sys.dm_exec_cached_plans (Transact-SQL)](../../relational-databases/system-dynamic-management-views/sys-dm-exec-cached-plans-transact-sql.md)
53-
[Server Configuration Options (SQL Server)](../../database-engine/configure-windows/server-configuration-options-sql-server.md)
54-
55-
55+
## See Also
56+
- [sys.dm_exec_cached_plans (Transact-SQL)](../../relational-databases/system-dynamic-management-views/sys-dm-exec-cached-plans-transact-sql.md)
57+
- [Server Configuration Options (SQL Server)](../../database-engine/configure-windows/server-configuration-options-sql-server.md)

0 commit comments

Comments
 (0)