liveBook · Manning

Query hint

As explained in 100 SQL Server Mistakes and How to Avoid Them

A query hint is a directive attached to a SQL Server query that influences or overrides query-optimizer decisions.

A query hint is a T-SQL directive that influences or overrides the SQL Server Query Optimizer. Use one only when the optimizer produces a demonstrably suboptimal plan; otherwise, work with the optimizer rather than against it. section 10.5

Mistake: forcing a join too quickly

A query joining Marketing.marketing.Impressions with MarketingArchive.dbo.ImpressionsArchive took 19 seconds because the plan used Nested Loops. Forcing a Hash Join changed the selected physical operator, but the safer first investigation is whether indexes on the join columns can improve the plan. Query hints can resolve exceptional performance problems, yet they may work against better decisions for different data or conditions. section 10.5

How 100 SQL Server Mistakes and How to Avoid Them covers it

How deep it goes
Defines optimizer override behavior and demonstrates join selection, but stops short of comprehensive hint syntax or optimizer internals.
Examples
Demonstrates a slow impressions join, a Nested Loops plan, a forced Hash Join, and indexes on join columns.
What it assumes
Assumes basic T-SQL joins and introduces optimizer decisions, physical join operators, and query-plan investigation.
What you can do after
Diagnose performance issues with execution plans and apply a join hint only after considering optimizer behavior and supporting indexes.
How it connects
Connects query hints with the Query Optimizer, execution plans, indexes, statistics, and physical join operators.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of 100 SQL Server Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.