Skip to content

Commit 27bb03e

Browse files
authored
Update best-practice-with-the-query-store.md
1 parent a1f7559 commit 27bb03e

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

docs/relational-databases/performance/best-practice-with-the-query-store.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Best Practice with the Query Store | Microsoft Docs"
33
ms.custom: ""
4-
ms.date: "11/29/2018"
4+
ms.date: "07/22/2019"
55
ms.prod: sql
66
ms.prod_service: "database-engine, sql-database"
77
ms.reviewer: ""
@@ -45,7 +45,7 @@ The default parameters are good enough to start, but you should monitor how Quer
4545

4646
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.
4747

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:
4949

5050
```sql
5151
USE [QueryStoreDB];
@@ -103,9 +103,9 @@ SET QUERY_STORE (SIZE_BASED_CLEANUP_MODE = AUTO);
103103

104104
**Query Store Capture Mode:** Specifies the query capture policy for the Query Store.
105105

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)].
107107

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.
109109

110110
- **None** - Query Store stops capturing new queries.
111111

@@ -240,7 +240,7 @@ FROM sys.database_query_store_options;
240240

241241
If the problem persists, it indicates corruption of the Query Store data is persisted on the disk.
242242

243-
For SQL 2017 and 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.
244244

245245
If that did not help, you can try to clear Query Store before requesting read-write mode.
246246

@@ -265,9 +265,12 @@ FROM sys.database_query_store_options;
265265

266266
|Query Capture Mode|Scenario|
267267
|------------------------|--------------|
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.|
270270
|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 &#40;Transact-SQL&#41;](../../t-sql/statements/alter-database-transact-sql-set-options.md).
271274

272275
## Keep the most relevant data in Query Store
273276
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:
304307
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 time and use plan forcing mechanism. To avoid this, use the `ALTER <object>` process to change a containing object definition whenever it is possible.
305308

306309
## <a name="CheckForced"></a> Check the status of Forced Plans regularly
307-
308310
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:
309311

310312
```sql
@@ -334,10 +336,14 @@ The global trace flags 7745 and 7752 can be used to improve availability of data
334336

335337
- 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.
336338

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+
337342
> [!IMPORTANT]
338343
> If you are using Query Store for just in time 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.
339344

340345
## See Also
346+
[ALTER DATABASE SET Options &#40;Transact-SQL&#41;](../../t-sql/statements/alter-database-transact-sql-set-options.md)
341347
[Query Store Catalog Views &#40;Transact-SQL&#41;](../../relational-databases/system-catalog-views/query-store-catalog-views-transact-sql.md)
342348
[Query Store Stored Procedures &#40;Transact-SQL&#41;](../../relational-databases/system-stored-procedures/query-store-stored-procedures-transact-sql.md)
343349
[Using the Query Store with In-Memory OLTP](../../relational-databases/performance/using-the-query-store-with-in-memory-oltp.md)

0 commit comments

Comments
 (0)