You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/relational-databases/performance/best-practice-with-the-query-store.md
+14-8Lines changed: 14 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: "Best Practice with the Query Store | Microsoft Docs"
3
3
ms.custom: ""
4
-
ms.date: "11/29/2018"
4
+
ms.date: "07/22/2019"
5
5
ms.prod: sql
6
6
ms.prod_service: "database-engine, sql-database"
7
7
ms.reviewer: ""
@@ -45,7 +45,7 @@ The default parameters are good enough to start, but you should monitor how Quer
45
45
46
46
While Query Store collects queries, execution plans and statistics, its size in the database grows until this limit is reached. When that happens, Query Store automatically changes the operation mode to read-only and stops collecting new data, which means that your performance analysis is no longer accurate.
47
47
48
-
The default value (100 MB) may not be sufficient if your workload generates large number of different queries and plans or if you want to keep query history for a longer period of time. Keep track of current space usage and increase the Max Size (MB) to prevent Query Store from transitioning to read-only mode. Use [!INCLUDE[ssManStudio](../../includes/ssmanstudio-md.md)] or execute the following script to get the latest information about Query Store size:
48
+
The default value in [!INCLUDE[ssSQL15](../../includes/sssql15-md.md)] and [!INCLUDE[ssSQL17](../../includes/sssql17-md.md)] is 100 MB, and may not be sufficient if your workload generates large number of different queries and plans or if you want to keep query history for a longer period of time. Starting with [!INCLUDE[sql-server-2019](../../includes/sssqlv15-md.md)], the default value is 1 GB. Keep track of current space usage and increase the Max Size (MB) to prevent Query Store from transitioning to read-only mode. Use [!INCLUDE[ssManStudio](../../includes/ssmanstudio-md.md)] or execute the following script to get the latest information about Query Store size:
49
49
50
50
```sql
51
51
USE [QueryStoreDB];
@@ -103,9 +103,9 @@ SET QUERY_STORE (SIZE_BASED_CLEANUP_MODE = AUTO);
103
103
104
104
**Query Store Capture Mode:** Specifies the query capture policy for the Query Store.
105
105
106
-
-**All** - Captures all queries. This is the default option.
106
+
-**All** - Captures all queries. This is the default option in [!INCLUDE[ssSQL15](../../includes/sssql15-md.md)] and [!INCLUDE[ssSQL17](../../includes/sssql17-md.md)].
107
107
108
-
-**Auto** - Infrequent queries and queries with insignificant compile and execution duration are ignored. Thresholds for execution count, compile and runtime duration are internally determined.
108
+
-**Auto** - Infrequent queries and queries with insignificant compile and execution duration are ignored. Thresholds for execution count, compile and runtime duration are internally determined. Starting with [!INCLUDE[sql-server-2019](../../includes/sssqlv15-md.md)], this is the default option.
109
109
110
110
-**None** - Query Store stops capturing new queries.
111
111
@@ -240,7 +240,7 @@ FROM sys.database_query_store_options;
240
240
241
241
If the problem persists, it indicates corruption of the Query Store data is persisted on the disk.
242
242
243
-
For SQL 2017and later, Query Store can be recovered by executing the **sp_query_store_consistency_check** stored procedure within the affected database. For 2016, you will need to clear the data from the Query Store as shown below.
243
+
Starting with [!INCLUDE[ssSQL17](../../includes/sssql17-md.md)], Query Store can be recovered by executing the **sp_query_store_consistency_check** stored procedure within the affected database. For [!INCLUDE[ssSQL15](../../includes/sssql15-md.md)], you will need to clear the data from the Query Store as shown below.
244
244
245
245
If that did not help, you can try to clear Query Store before requesting read-write mode.
246
246
@@ -265,9 +265,12 @@ FROM sys.database_query_store_options;
265
265
266
266
|Query Capture Mode|Scenario|
267
267
|------------------------|--------------|
268
-
|All|Analyze your workload thoroughly in terms of all queries shapes and their execution frequencies and other statistics.<br /><br /> Identify new queries in your workload.<br /><br /> Detect if ad-hoc queries are used to identify opportunities for user or auto parameterization.|
269
-
|Auto|Focus your attention on relevant and actionable queries; those queries that execute regularly or that have significant resource consumption.|
268
+
|All|Analyze your workload thoroughly in terms of all queries shapes and their execution frequencies and other statistics.<br /><br /> Identify new queries in your workload.<br /><br /> Detect if ad-hoc queries are used to identify opportunities for user or auto parameterization.<br /><br />**Note:** This is the default capture mode in [!INCLUDE[ssSQL15](../../includes/sssql15-md.md)] and [!INCLUDE[ssSQL17](../../includes/sssql17-md.md)].|
269
+
|Auto|Focus your attention on relevant and actionable queries; those queries that execute regularly or that have significant resource consumption.<br /><br />**Note:** Starting with [!INCLUDE[sql-server-2019](../../includes/sssqlv15-md.md)] this is the default capture mode.|
270
270
|None|You have already captured the query set that you want to monitor in runtime and you want to eliminate the distractions that other queries may introduce.<br /><br /> None is suitable for testing and bench-marking environments.<br /><br /> None is also appropriate for software vendors who ship Query Store configuration configured to monitor their application workload.<br /><br /> None should be used with caution as you might miss the opportunity to track and optimize important new queries. Avoid using None unless you have a specific scenario that requires it.|
271
+
272
+
> [!IMPORTANT]
273
+
> [!INCLUDE[sql-server-2019](../../includes/sssqlv15-md.md)] CTP 3.1 introduces a CUSTOM capture mode under the `ALTER DATABASE SET QUERY_STORE` command. When enabled, additional Query Store configurations are available under a new Query Store Capture Policy setting, to fine tune data collection in a specific server. The new custom settings define what happens during the internal capture policy time threshold: a time boundary during which the configurable conditions are evaluated and if any are true, the query is eligible to be captured by Query Store. For more information, see [ALTER DATABASE SET Options (Transact-SQL)](../../t-sql/statements/alter-database-transact-sql-set-options.md).
271
274
272
275
## Keep the most relevant data in Query Store
273
276
Configure the Query Store to contain only the relevant data and it will run continuously providing great troubleshooting experience with a minimal impact on your regular workload.
@@ -304,7 +307,6 @@ Consider following options:
304
307
Query Store associates query entry with a containing object (stored procedure, function, and trigger). When you recreate a containing object, a new query entry will be generated for the same query text. This will prevent you from tracking performance statistics for that query over timeand use plan forcing mechanism. To avoid this, use the `ALTER <object>` process to change a containing object definition whenever it is possible.
305
308
306
309
## <a name="CheckForced"></a> Check the status of Forced Plans regularly
307
-
308
310
Plan forcing is a convenient mechanism to fix performance for the critical queries and make them more predictable. However, as with plan hints and plan guides, forcing a plan is not a guarantee that it will be used in future executions. Typically, when database schema changes in a way that objects referenced by the execution plan are altered or dropped, plan forcing will start failing. In that case [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] falls back to query recompilation while the actual forcing failure reason is surfaced in [sys.query_store_plan](../../relational-databases/system-catalog-views/sys-query-store-plan-transact-sql.md). The following query returns information about forced plans:
309
311
310
312
```sql
@@ -334,10 +336,14 @@ The global trace flags 7745 and 7752 can be used to improve availability of data
334
336
335
337
- Trace flag 7752 enables asynchronous load of Query Store. This allows a database to become online and queries to be executed before the Query Store has been fully recovered. The default behavior is to do a synchronous load of Query Store. The default behavior prevents queries from executing before the Query Store has been recovered but also prevents any queries from being missed in the data collection.
336
338
339
+
> [!NOTE]
340
+
> Starting with [!INCLUDE[sql-server-2019](../../includes/sssqlv15-md.md)], this behavior is controlled by the engine and trace flag 7752 has no effect.
341
+
337
342
> [!IMPORTANT]
338
343
> If you are using Query Store for just intime workload insights in [!INCLUDE[ssSQL15](../../includes/sssql15-md.md)], plan to install the performance scalability fixes in [KB 4340759](https://support.microsoft.com/help/4340759) as soon as possible.
339
344
340
345
## See Also
346
+
[ALTER DATABASE SET Options (Transact-SQL)](../../t-sql/statements/alter-database-transact-sql-set-options.md)
341
347
[Query Store Catalog Views (Transact-SQL)](../../relational-databases/system-catalog-views/query-store-catalog-views-transact-sql.md)
342
348
[Query Store Stored Procedures (Transact-SQL)](../../relational-databases/system-stored-procedures/query-store-stored-procedures-transact-sql.md)
343
349
[Using the Query Store with In-Memory OLTP](../../relational-databases/performance/using-the-query-store-with-in-memory-oltp.md)
0 commit comments