Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit 2eec718

Browse files
authored
Adding info on QUERYTRACEON hint
1 parent e14542e commit 2eec718

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

docs/t-sql/queries/hints-transact-sql-query.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ Query hints specify that the indicated hints should be used throughout the query
9999
| OPTIMIZE FOR ( @variable_name { UNKNOWN | = literal_constant } [ , ...n ] )
100100
| OPTIMIZE FOR UNKNOWN
101101
| PARAMETERIZATION { SIMPLE | FORCED }
102+
| QUERYTRACEON trace_flag
102103
| RECOMPILE
103104
| ROBUST PLAN
104105
| USE HINT ( '<hint_name>' [ , ...n ] )
@@ -235,7 +236,12 @@ OPTIMIZE FOR UNKNOWN
235236
Instructs the Query Optimizer to use statistical data instead of the initial values for all local variables when the query is compiled and optimized. This optimization includes parameters created with forced parameterization.
236237

237238
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.
238-
239+
240+
QUERYTRACEON trace_flag
241+
This option lets you to 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 that are documented in the table of "More information" section and in [Trace Flags](../database-console-commands/dbcc-traceon-trace-flags-transact-sql.md). However, this option will not return any error or warning if an unsupported trace flag number is used. If the specified trace flag is not one that affects a query execution plan, the option will be silently ignored.
242+
243+
More than one trace flag can be specified in the OPTION clause if QUERYTRACEON trace_flag_number is duplicated with different trace flag numbers.
244+
239245
PARAMETERIZATION { SIMPLE | FORCED }
240246
Specifies the parameterization rules that the [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] Query Optimizer applies to the query when it's compiled.
241247

@@ -596,7 +602,24 @@ WHERE City = 'SEATTLE' AND PostalCode = 98104
596602
OPTION (RECOMPILE, USE HINT ('ASSUME_MIN_SELECTIVITY_FOR_FILTER_ESTIMATES', 'DISABLE_PARAMETER_SNIFFING'));
597603
GO
598604
```
599-
605+
### M. Using QUERYTRACEON HINT
606+
The following example uses the QUERYTRACEON query hints. The example uses the [!INCLUDE[ssSampleDBobject](../../includes/sssampledbobject-md.md)] database. You can enable all plan-affecting hotfixes controlled by trace flag 4199 for a particular query using the following query:
607+
608+
```sql
609+
SELECT * FROM Person.Address
610+
WHERE City = 'SEATTLE' AND PostalCode = 98104
611+
OPTION (QUERYTRACEON 4199);
612+
```
613+
614+
You can use multiple trace flags as well as in teh following query:
615+
616+
```sql
617+
SELECT * FROM Person.Address
618+
WHERE City = 'SEATTLE' AND PostalCode = 98104
619+
OPTION (QUERYTRACEON 4199, QUERYTRACEON 4137);
620+
```
621+
622+
600623
## See Also
601624
[Hints &#40;Transact-SQL&#41;](../../t-sql/queries/hints-transact-sql.md)
602625
[sp_create_plan_guide &#40;Transact-SQL&#41;](../../relational-databases/system-stored-procedures/sp-create-plan-guide-transact-sql.md)

0 commit comments

Comments
 (0)