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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

OPTION ( FAST 10 );<br />

Listing 5.16<br />

Figure 5.12<br />

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

Instead of the Merge Join operator for the join, the optimizer attempts to use a Nested<br />

Loops operator. The loop join returns the first rows very fast, but the rest of the<br />

processing was somewhat slower, which is perhaps to be expected, since the optimizer<br />

focuses its efforts just on getting the first ten rows back as soon as possible.<br />

The total estimated cost for the original query was 1.961. The hint reduced that cost to<br />

0.012 (for the first 10 rows). The number of logical reads increases dramatically, from 1,238<br />

for the un-hinted query to 101,827 for the hinted query. The actual speed of the execution<br />

of the query increases only marginally, from around 4.6 seconds to 4.5 seconds. This slight<br />

improvement is only going to get the first few rows back to the screen quickly. The overall<br />

query won't run as fast once there is a load on the system and this query has to share disk<br />

access with other queries, because of all those additional reads.<br />

FORCE ORDER<br />

Once again, our monitoring tools have identified a query that is performing poorly. It's<br />

a long query with a number of tables being joined, as shown in Listing 5.17, which could<br />

be somewhat concerning, because the more tables there are involved, the harder the<br />

optimizer has to work.<br />

191

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

Saved successfully!

Ooh no, something went wrong!