Replace Trace Flag with ‘USE HINT’

January 23, 2021

Introduced in SQL Server 2016 (13.x) SP1 and Azure SQL Database is the USE HINT option. At the time of writing this article, there are 23 of those. You can see an up to date list by running Dynamic Management View sys.dm_exec_valid_use_hints.

With the introduction of this feature, we can replace some of the trace flags with hints. I personally like hints over trace flags (if I have to choose between two devils). That way someone reading the code have some idea what the hint is about instead of remembering the trace flag numbers.

Here is a list of Trace Flags and Hints that we can replace:

Trace FlagHint
9476ASSUME_JOIN_PREDICATE_DEPENDS_ON_FILTERS
4137SQL Server 2012 (11.x) and earlier versions
ASSUME_MIN_SELECTIVITY_FOR_FILTER_ESTIMATES
9471SQL Server 2014 (12.x) or higher
ASSUME_MIN_SELECTIVITY_FOR_FILTER_ESTIMATES
2340DISABLE_OPTIMIZED_NESTED_LOOP
4138DISABLE_OPTIMIZER_ROWGOAL
4136DISABLE_PARAMETER_SNIFFING
4139ENABLE_HIST_AMENDMENT_FOR_ASC_KEYS
4199ENABLE_QUERY_OPTIMIZER_HOTFIXES
9481FORCE_DEFAULT_CARDINALITY_ESTIMATION
FORCE_LEGACY_CARDINALITY_ESTIMATION

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.