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/t-sql/queries/hints-transact-sql-query.md
+29-37Lines changed: 29 additions & 37 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -181,7 +181,7 @@ Optimized plan forcing reduces compilation overhead for repeating forced queries
181
181
182
182
#### EXPAND VIEWS
183
183
184
-
Specifies the indexed views are expanded. Also specifies the Query Optimizer won't consider any indexed view as a replacement for any query part. A view is expanded when the view definition replaces the view name in the query text.
184
+
Specifies the indexed views are expanded. Also specifies the Query Optimizer doesn't consider any indexed view as a replacement for any query part. A view is expanded when the view definition replaces the view name in the query text.
185
185
186
186
This query hint virtually disallows direct use of indexed views and indexes on indexed views in the query plan.
187
187
@@ -207,20 +207,18 @@ Force or disable the pushdown of the computation of qualifying expressions in Ha
207
207
208
208
#### { FORCE | DISABLE } SCALEOUTEXECUTION
209
209
210
-
Force or disable scale out execution of PolyBase queries that are using external tables in SQL Server 2019 Big Data Clusters. This hint will only be honored by a query using the master instance of a SQL big data cluster. The scale out will occur across the compute pool of the big data cluster.
210
+
Force or disable scale out execution of PolyBase queries that are using external tables in SQL Server 2019 Big Data Clusters. This hint is only honored by a query using the master instance of a SQL Big Data Cluster. The scale out occurs across the compute pool of the big data cluster.
211
211
212
212
#### KEEP PLAN
213
213
214
214
Changes the [recompilation thresholds](../../relational-databases/statistics/statistics.md#auto_update_statistics-option) for temporary tables, and makes them identical to those for permanent tables. The estimated recompile threshold starts an automatic recompile for the query when the estimated number of indexed column changes have been made to a table by running one of the following statements:
215
215
216
-
#### - UPDATE
217
-
218
-
#### - DELETE
219
-
216
+
- UPDATE
217
+
- DELETE
220
218
- MERGE
221
219
- INSERT
222
220
223
-
Specifying KEEP PLAN makes sure a query won't be recompiled as frequently when there are multiple updates to a table.
221
+
Specifying KEEP PLAN makes sure a query isn't recompiled as frequently when there are multiple updates to a table.
224
222
225
223
#### KEEPFIXED PLAN
226
224
@@ -236,23 +234,21 @@ Prevents the query from using a nonclustered memory optimized columnstore index.
236
234
237
235
**Applies to**: [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] (starting with [!INCLUDE [ssSQL11](../../includes/sssql11-md.md)] Service Pack 3, [!INCLUDE [ssSQL14](../../includes/sssql14-md.md)] Service Pack 2 and [!INCLUDE [ssazure-sqldb](../../includes/ssazure-sqldb.md)].
238
236
239
-
The maximum memory grant size in PERCENT of configured memory limit. The query is guaranteed not to exceed this limit if the query is running in a user defined resource pool. In this case, if the query does not have the minimum required memory the system will raise an error. If a query is running in the system pool (default), then it will get at minimum the memory required to run. The actual limit can be lower if the Resource Governor setting is lower than the value specified by this hint. Valid values are between 0.0 and 100.0.
237
+
The maximum memory grant size in PERCENT of configured memory limit. The query is guaranteed not to exceed this limit if the query is running in a user defined resource pool. In this case, if the query doesn't have the minimum required memory the system raises an error. If a query is running in the system pool (default), then it gets at minimum the memory required to run. The actual limit can be lower if the Resource Governor setting is lower than the value specified by this hint. Valid values are between 0.0 and 100.0.
240
238
241
-
The memory grant hint isn't available for index creation or rebuild.
239
+
The memory grant hint isn't available for index creation or index rebuilding.
242
240
243
241
#### MIN_GRANT_PERCENT = <numeric_value>
244
242
245
243
**Applies to**: [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] (starting with [!INCLUDE [ssSQL11](../../includes/sssql11-md.md)] Service Pack 3, [!INCLUDE [ssSQL14](../../includes/sssql14-md.md)] Service Pack 2 and [!INCLUDE [ssazure-sqldb](../../includes/ssazure-sqldb.md)].
246
244
247
245
The minimum memory grant size in PERCENT of configured memory limit. The query is guaranteed to get `MAX(required memory, min grant)` because at least required memory is needed to start a query. Valid values are between 0.0 and 100.0.
248
246
249
-
#### The min_grant_percent memory grant option overrides the `sp_configure` option (minimum memory per query (KB)) regardless of the size.
250
-
251
-
The memory grant hint isn't available for index creation or rebuild.
247
+
The min_grant_percent memory grant option overrides the `sp_configure` option (minimum memory per query (KB)) regardless of the size. The memory grant hint isn't available for index creation or index rebuilding.
252
248
253
249
#### MAXDOP <integer_value>
254
250
255
-
**Applies to**: [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] (starting with [!INCLUDE [sql2008-md](../../includes/sql2008-md.md)]) and [!INCLUDE [ssSDSfull](../../includes/sssdsfull-md.md)].
251
+
**Applies to**: [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] (starting with [!INCLUDE [sql2008-md](../../includes/sql2008-md.md)]) and [!INCLUDE [ssazure-sqldb](../../includes/ssazure-sqldb.md)].
256
252
257
253
Overrides the **max degree of parallelism** configuration option of `sp_configure`. Also overrides the Resource Governor for the query specifying this option. The MAXDOP query hint can exceed the value configured with `sp_configure`. If MAXDOP exceeds the value configured with Resource Governor, the [!INCLUDE [ssDE](../../includes/ssde-md.md)] uses the Resource Governor MAXDOP value, described in [ALTER WORKLOAD GROUP (Transact-SQL)](../statements/alter-workload-group-transact-sql.md). All semantic rules used with the **max degree of parallelism** configuration option are applicable when you use the MAXDOP query hint. For more information, see [Configure the max degree of parallelism Server Configuration Option](../../database-engine/configure-windows/configure-the-max-degree-of-parallelism-server-configuration-option.md).
258
254
@@ -271,7 +267,7 @@ For more information, see [WITH common_table_expression (Transact-SQL)](../queri
271
267
272
268
#### NO_PERFORMANCE_SPOOL
273
269
274
-
**Applies to**: [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] (starting with [!INCLUDE [sssql16-md](../../includes/sssql16-md.md)]) and [!INCLUDE [ssSDSfull](../../includes/sssdsfull-md.md)].
270
+
**Applies to**: [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] (starting with [!INCLUDE [sssql16-md](../../includes/sssql16-md.md)]) and [!INCLUDE [ssazure-sqldb](../../includes/ssazure-sqldb.md)].
275
271
276
272
Prevents a spool operator from being added to query plans (except for the plans when spool is required to guarantee valid update semantics). The spool operator may reduce performance in some scenarios. For example, the spool uses `tempdb`, and `tempdb` contention can occur if there are many concurrent queries running with the spool operations.
277
273
@@ -297,7 +293,7 @@ OPTIMIZE FOR can counteract the optimizer's default parameter detection behavior
297
293
298
294
Instructs the Query Optimizer to use the average selectivity of the predicate across all column values instead of using the runtime parameter value when the query is compiled and optimized.
299
295
300
-
If you use `OPTIMIZE FOR @variable_name = <literal_constant>` and `OPTIMIZE FOR UNKNOWN` in the same query hint, the Query Optimizer will use the *literal_constant* specified for a specific value. The Query Optimizer will use UNKNOWN for the rest of the variable values. The values are used only during query optimization, and not during query execution.
296
+
If you use `OPTIMIZE FOR @variable_name = <literal_constant>` and `OPTIMIZE FOR UNKNOWN` in the same query hint, the Query Optimizer uses the *literal_constant* specified for a specific value. The Query Optimizer uses UNKNOWN for the rest of the variable values. The values are used only during query optimization, and not during query execution.
301
297
302
298
#### PARAMETERIZATION { SIMPLE | FORCED }
303
299
@@ -314,7 +310,7 @@ SIMPLE instructs the Query Optimizer to attempt simple parameterization. FORCED
314
310
315
311
This option lets you enable a plan-affecting trace flag only during single-query compilation. Like other query-level options, you can use it together with plan guides to match the text of a query being executed from any session, and automatically apply a plan-affecting trace flag when this query is being compiled. The QUERYTRACEON option is only supported for Query Optimizer trace flags. For more information, see [Trace Flags](../database-console-commands/dbcc-traceon-trace-flags-transact-sql.md).
316
312
317
-
Using this option won't return any error or warning if an unsupported trace flag number is used. If the specified trace flag isn't one that affects a query execution plan, the option will be silently ignored.
313
+
Using this option won't return any error or warning if an unsupported trace flag number is used. If the specified trace flag isn't one that affects a query execution plan, the option is silently ignored.
318
314
319
315
To use more than one trace flag in a query, specify one QUERYTRACEON hint for each different trace flag number.
320
316
@@ -332,7 +328,7 @@ If such a plan isn't possible, the Query Optimizer returns an error instead of d
332
328
333
329
#### <aid="use_hint"></a> USE HINT ( '*hint_name*' )
334
330
335
-
**Applies to**: [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] (starting with [!INCLUDE [sssql16-md](../../includes/sssql16-md.md)] SP1) and [!INCLUDE [ssSDSfull](../../includes/sssdsfull-md.md)].
331
+
**Applies to**: [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] (starting with [!INCLUDE [sssql16-md](../../includes/sssql16-md.md)] SP1) and [!INCLUDE [ssazure-sqldb](../../includes/ssazure-sqldb.md)].
336
332
337
333
Provides one or more additional hints to the query processor. The additional hints are specified by a hint name **inside single quotation marks**.
338
334
@@ -350,37 +346,37 @@ The following hint names are supported:
350
346
351
347
Causes [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] to generate a plan using maximum selectivity when estimating AND predicates for filters to account for full independence. This hint name is the default behavior of the cardinality estimation model of [!INCLUDE [ssSQL11](../../includes/sssql11-md.md)] and earlier versions, and equivalent to [trace flag](../database-console-commands/dbcc-traceon-trace-flags-transact-sql.md) 9472 when used with cardinality estimation model of [!INCLUDE [ssSQL14](../../includes/sssql14-md.md)] or higher.
Causes [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] to generate a plan using most to least selectivity when estimating AND predicates for filters to account for partial correlation. This hint name is the default behavior of the cardinality estimation model of [!INCLUDE [ssSQL14](../../includes/sssql14-md.md)] or higher.
Disables batch mode adaptive joins. For more information, see [Batch mode Adaptive Joins](../../relational-databases/performance/intelligent-query-processing-details.md#batch-mode-adaptive-joins).
364
360
365
-
**Applies to**: [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] (starting with [!INCLUDE [ssSQL17](../../includes/sssql17-md.md)]) and [!INCLUDE [ssSDSfull](../../includes/sssdsfull-md.md)]
361
+
**Applies to**: [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] (starting with [!INCLUDE [ssSQL17](../../includes/sssql17-md.md)]) and [!INCLUDE [ssazure-sqldb](../../includes/ssazure-sqldb.md)]
366
362
367
363
- 'DISABLE_BATCH_MODE_MEMORY_GRANT_FEEDBACK'
368
364
369
365
Disables batch mode memory grant feedback. For more information, see [Batch mode memory grant feedback](../../relational-databases/performance/intelligent-query-processing-feedback.md#batch-mode-memory-grant-feedback).
370
366
371
-
**Applies to**: [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] (starting with [!INCLUDE [ssSQL17](../../includes/sssql17-md.md)]) and [!INCLUDE [ssSDSfull](../../includes/sssdsfull-md.md)]
367
+
**Applies to**: [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] (starting with [!INCLUDE [ssSQL17](../../includes/sssql17-md.md)]) and [!INCLUDE [ssazure-sqldb](../../includes/ssazure-sqldb.md)]
372
368
373
369
- 'DISABLE_DEFERRED_COMPILATION_TV'
374
370
375
371
Disables table variable deferred compilation. For more information, see [Table variable deferred compilation](../../relational-databases/performance/intelligent-query-processing-details.md#table-variable-deferred-compilation).
376
372
377
-
**Applies to**: [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] (starting with [!INCLUDE [sql-server-2019](../../includes/sssql19-md.md)]) and [!INCLUDE [ssSDSfull](../../includes/sssdsfull-md.md)]
373
+
**Applies to**: [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] (starting with [!INCLUDE [sql-server-2019](../../includes/sssql19-md.md)]) and [!INCLUDE [ssazure-sqldb](../../includes/ssazure-sqldb.md)]
378
374
379
375
- 'DISABLE_INTERLEAVED_EXECUTION_TVF'
380
376
381
377
Disables interleaved execution for multi-statement table-valued functions. For more information, see [Interleaved execution for multi-statement table-valued functions](../../relational-databases/performance/intelligent-query-processing-details.md#interleaved-execution-for-mstvfs).
382
378
383
-
**Applies to**: [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] (starting with [!INCLUDE [ssSQL17](../../includes/sssql17-md.md)]) and [!INCLUDE [ssSDSfull](../../includes/sssdsfull-md.md)]
379
+
**Applies to**: [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] (starting with [!INCLUDE [ssSQL17](../../includes/sssql17-md.md)]) and [!INCLUDE [ssazure-sqldb](../../includes/ssazure-sqldb.md)]
384
380
385
381
- 'DISABLE_OPTIMIZED_NESTED_LOOP'
386
382
@@ -390,12 +386,10 @@ The following hint names are supported:
390
386
391
387
Causes SQL Server to generate a plan that doesn't use row goal modifications with queries that contain these keywords:
392
388
393
-
#### - TOP
394
-
395
-
#### - OPTION (FAST N)
396
-
389
+
- TOP
390
+
- OPTION (FAST N)
397
391
- IN
398
-
- EXISTS
392
+
- EXISTS
399
393
400
394
This hint name is equivalent to [trace flag](../database-console-commands/dbcc-traceon-trace-flags-transact-sql.md) 4138.
401
395
@@ -407,19 +401,19 @@ The following hint names are supported:
407
401
408
402
Disables row mode memory grant feedback. For more information, see [Row mode memory grant feedback](../../relational-databases/performance/intelligent-query-processing-feedback.md#row-mode-memory-grant-feedback).
409
403
410
-
**Applies to**: [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] (starting with [!INCLUDE [sql-server-2019](../../includes/sssql19-md.md)]) and [!INCLUDE [ssSDSfull](../../includes/sssdsfull-md.md)]
404
+
**Applies to**: [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] (starting with [!INCLUDE [sql-server-2019](../../includes/sssql19-md.md)]) and [!INCLUDE [ssazure-sqldb](../../includes/ssazure-sqldb.md)]
411
405
412
406
- 'DISABLE_TSQL_SCALAR_UDF_INLINING'
413
407
414
408
Disables scalar UDF inlining. For more information, see [Scalar UDF Inlining](../../relational-databases/user-defined-functions/scalar-udf-inlining.md).
415
409
416
-
**Applies to**: [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] (starting with [!INCLUDE [sql-server-2019](../../includes/sssql19-md.md)]) and [!INCLUDE [ssSDSfull](../../includes/sssdsfull-md.md)]
410
+
**Applies to**: [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] (starting with [!INCLUDE [sql-server-2019](../../includes/sssql19-md.md)]) and [!INCLUDE [ssazure-sqldb](../../includes/ssazure-sqldb.md)]
417
411
418
412
- 'DISALLOW_BATCH_MODE'
419
413
420
414
Disables batch mode execution. For more information, see [Execution modes](../../relational-databases/query-processing-architecture-guide.md#execution-modes).
421
415
422
-
**Applies to**: [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] (starting with [!INCLUDE [sql-server-2019](../../includes/sssql19-md.md)]) and [!INCLUDE [ssSDSfull](../../includes/sssdsfull-md.md)]
416
+
**Applies to**: [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] (starting with [!INCLUDE [sql-server-2019](../../includes/sssql19-md.md)]) and [!INCLUDE [ssazure-sqldb](../../includes/ssazure-sqldb.md)]
423
417
424
418
- 'ENABLE_HIST_AMENDMENT_FOR_ASC_KEYS'
425
419
@@ -441,7 +435,7 @@ The following hint names are supported:
441
435
442
436
Forces the Query Optimizer behavior at a query level. This behavior happens as if the query was compiled with database compatibility level *n*, where *n* is a supported database compatibility level (for example 100, 130, etc.). Refer to [sys.dm_exec_valid_use_hints](../../relational-databases/system-dynamic-management-views/sys-dm-exec-valid-use-hints-transact-sql.md) for a list of currently supported values for *n*.
443
437
444
-
**Applies to**: [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] (starting with [!INCLUDE [ssSQL17](../../includes/sssql17-md.md)] CU10) and [!INCLUDE [ssSDSfull](../../includes/sssdsfull-md.md)]
438
+
**Applies to**: [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] (starting with [!INCLUDE [ssSQL17](../../includes/sssql17-md.md)] CU10) and [!INCLUDE [ssazure-sqldb](../../includes/ssazure-sqldb.md)]
445
439
446
440
> [!NOTE]
447
441
> The QUERY_OPTIMIZER_COMPATIBILITY_LEVEL_n hint doesn't override default or legacy cardinality estimation setting, if it's forced through database scoped configuration, trace flag or another query hint such as QUERYTRACEON.
@@ -486,7 +480,7 @@ Applies the specified table hint to the table or view that corresponds to *expos
486
480
487
481
When you specify *exposed_object_name* without also specifying a table hint, any indexes you specify in the query as part of a table hint for the object are disregarded. The Query Optimizer then determines index usage. You can use this technique to eliminate the effect of an INDEX table hint when you can't modify the original query. See Example J.
0 commit comments