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><br />

with Hints<br />

It is possible, using various available hints, to impose your will on the optimizer and, to<br />

some degree, control its behavior. There are three categories of hints, which include:<br />

• Query hints tell the optimizer to apply a hint throughout the execution of the<br />

entire query.<br />

• Join hints tell the optimizer to use a particular join at a particular point in the query.<br />

• Table hints control Table Scans and the use of a particular index for a table.<br />

In this chapter, I'll describe how to use each type of hint, but I can't stress the following<br />

enough: hints are dangerous. Hints detract from the optimizer's ability to make choices.<br />

Appropriate use of the right hint on the right query can improve query performance. The<br />

exact same hint used on another query can create more problems than it solves, radically<br />

slowing your query and leading to severe blocking and timeouts in your application.<br />

If you find yourself putting hints on a majority of your queries and stored procedures,<br />

then you're doing something wrong. As part of describing what the hints do, I'll lay out<br />

the problem that you're hoping to solve by applying that hint. Some of the examples<br />

will improve performance or change the behavior in a positive manner, and some will<br />

negatively affect performance.<br />

177

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

Saved successfully!

Ooh no, something went wrong!