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/query-store-hints-best-practices.md
+26-14Lines changed: 26 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,48 +24,59 @@ This article details best practices for using [Query Store hints (Preview)](quer
24
24
- For more information on configuring and administering with the Query Store, see [Monitoring performance by using the Query Store](monitoring-performance-by-using-the-query-store.md).
25
25
- For information on discovering actionable information and tune performance with the Query Store, see [Tuning performance by using the Query Store](tune-performance-with-the-query-store.md).
26
26
27
-
Learn how to improve bulk loading with Query Store hints with this 14-minute video:
Consider the following use cases as ideal of Query Store hints. For more information, see [When to use Query Store hints](query-store-hints.md#when-to-use-query-store-hints).
34
30
35
31
> [!CAUTION]
36
32
> Because the SQL Server Query Optimizer typically selects the best execution plan for a query, we recommend only using hints as a last resort for experienced developers and database administrators. For more information, see [Query Hints](../../t-sql/queries/hints-transact-sql-query.md).
37
33
38
-
### Code cannot be changed
34
+
### When code cannot be changed
39
35
40
36
Using Query Store hints allows you to influence the execution plans of queries without changing application code or database objects. No other feature allows for you to apply query hints quickly and easily.
41
37
38
+
You can use Query Store hints, for example, to benefit ETLs without redeploying code. Learn how to improve bulk loading with Query Store hints with this 14-minute video:
Query Store hints are lightweight query tuning methods, but if a query becomes problematic it should be addressed with more substantial code changes. If you are regularly finding the need to apply Query Store hints to a query, consider a larger query rewrite. The SQL Server Query Optimizer typically selects the best execution plan for a query, we recommend only using hints as a last resort for experienced developers and database administrators.
43
+
42
44
For information on which query hints can be applied, see [Supported query hints](../system-stored-procedures/sys-sp-query-store-set-hints-transact-sql.md#supported-query-hints).
43
45
44
-
### High transaction load, mission critical code
46
+
### Under high transaction load or with mission critical code
45
47
46
48
If code changes are impractical because of high uptime requirements or transactional load, Query Store hints can apply query hints to existing query workloads quickly. Adding and removing Query Store hints is easy.
47
49
48
50
Query Store hints can be added and removed to batches of queries to adjust performance for windows timed for bursts of exceptional workload.
49
51
50
-
### Replacement for plan guides
52
+
### As a replacement for plan guides
51
53
52
54
Previous to Query Store hints, a developer would have to rely on [plan guides](plan-guides.md) to accomplish similar tasks, which can be complex to use. Query Store hints are integrated with Query Store features of SQL Server Management Studio (SSMS), for visual exploration of queries.
53
55
54
56
With plan guides, searching through all plans using query snippets is necessary. The Query Store hints feature does not require exact matching queries to impact the resulting query plan. Query Store hints can be applied to a `query_id` in the Query Store dataset.
55
57
56
58
Query Store hints override hard-coded statement-level hints and existing plan guides.
57
59
58
-
## Query Store hints caveats
59
-
60
-
Query Store hints are lightweight query tuning methods, but if a query becomes problematic it should be addressed with more substantial code changes. If you are regularly finding the need to apply Query Store hints to a query, consider a larger query rewrite. The SQL Server Query Optimizer typically selects the best execution plan for a query, we recommend only using hints as a last resort for experienced developers and database administrators.
61
-
62
60
### Consider a newer compatibility level
63
61
64
62
Query Store hints can be a valuable method when a newer database compatibility level is not available to you due to vendor specification or larger testing delays, for example. When a higher compatibility level is available to a database, consider upgrading the database compatibility level to take advantage of the latest performance optimizations and features of SQL Server.
65
63
64
+
## Query Store hints considerations
65
+
66
+
Consider the following scenarios when deploying Query Store hints.
67
+
66
68
### Data distribution changes
67
69
68
-
Plan guides, forced plans via the Query Store, and Query Store hints override the optimizer's decision making. For example, if a Query Store hint helps a query in previous data distribution, it may be counter-productive if large-scale DML operations change the data. A new data distribution may cause the optimizer to make a better decision than the hint. This scenario is the most common consequence of forcing plan behavior.
70
+
Plan guides, forced plans via the Query Store, and Query Store hints override the optimizer's decision making. The Query Store hint may be beneficial now, but not in the future. For example, if a Query Store hint helps a query in previous data distribution, it may be counter-productive if large-scale DML operations change the data. A new data distribution may cause the optimizer to make a better decision than the hint. This scenario is the most common consequence of forcing plan behavior.
71
+
72
+
### Regularly re-evaluate your Query Store hints strategy
73
+
74
+
Re-evaluate your existing Query Store hints strategy in the following cases:
75
+
76
+
- After known large data distribution changes.
77
+
- When the service level objective (SLO) of your Azure SQL Database or Managed Instance or virtual machine has changed.
78
+
- Where plan fixing has become long-lived. Query Store hints are best used for short-term fixes.
79
+
- Unexpected performance regressions.
69
80
70
81
### Broad impact potential
71
82
@@ -79,8 +90,9 @@ Applying the RECOMPILE query hint with Query Store hints is not supported when t
79
90
80
91
The RECOMPILE hint is not compatible with forced parameterization set at the database level. If the database has forced parameterization set, and the RECOMPILE hint is part of the hints string set in Query Store for a query, the Database Engine will ignore the RECOMPILE hint and will apply other hints if leveraged.
81
92
82
-
<!-- t63 warning-->
93
+
For information on which query hints can be applied, see [Supported query hints](../system-stored-procedures/sys-sp-query-store-set-hints-transact-sql.md#supported-query-hints).
0 commit comments