30.06.2013 Views

SQL Server Execution Plans - Red Gate Software

SQL Server Execution Plans - Red Gate Software

SQL Server Execution Plans - Red Gate Software

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 5: Controlling <strong>Execution</strong> <strong>Plans</strong> with Hints<br />

LOOP|MERGE|HASH JOIN<br />

These hint methods make all the join operations in a particular query use the method<br />

supplied by the hint. However, note that, if we also apply a join hint (covered later) to<br />

a specific join, then the more granular join hint takes precedence over the general<br />

query hint.<br />

In this situation, we've found that our system is suffering from poor disk I/O, so we need<br />

to reduce the number of scans and reads that our queries generate. By collecting data<br />

from Profiler and Performance Monitor, we identify the query in Listing 5.7 as one that<br />

needs some tuning.<br />

SELECT pm.Name ,<br />

pm.CatalogDescription ,<br />

p.Name AS ProductName ,<br />

i.Diagram<br />

FROM Production.ProductModel AS pm<br />

LEFT JOIN Production.Product AS p<br />

ON pm.ProductModelID = p.ProductModelID<br />

LEFT JOIN Production.ProductModelIllustration AS pmi<br />

ON p.ProductModelID = pmi.ProductModelID<br />

LEFT JOIN Production.Illustration AS i<br />

ON pmi.IllustrationID = i.IllustrationID<br />

WHERE pm.Name LIKE '%Mountain%'<br />

ORDER BY pm.Name;<br />

Listing 5.7<br />

185

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!