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

The performance penalty comes from the fact that there was a single scan and two reads<br />

on the ProductModel table in the original query. Use of the Nested Loops join changed<br />

the behavior to a single scan with 1,009 reads. Reading more data will have an impact on<br />

the performance of queries.<br />

Summary<br />

While the optimizer makes very good decisions most of the time, it may sometimes make<br />

less than optimal choices. Taking control of the queries using Table, Join and Query hints,<br />

when appropriate, can often be the right choice. However, remember that the data in<br />

your database is constantly changing. Any choices you force on the optimizer through<br />

hints today, to achieve whatever improvement you're hoping for, may become a major<br />

pain in the future.<br />

If you decide to use hints, test them prior to applying them, and remember to document<br />

their use in some manner so that you can come back and test them again periodically as<br />

your database grows. As Microsoft releases patches and service packs, the behavior of the<br />

optimizer can change. Be sure to retest any queries using hints after an upgrade to your<br />

server. I intentionally demonstrated cases where the query hints hurt as well as help,<br />

as this simply reflects reality. Use of these hints should be a last resort, not a standard<br />

method of operation.<br />

226

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

Saved successfully!

Ooh no, something went wrong!