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.

FAST n<br />

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

Let's assume that we are not concerned about the performance of the database. This time,<br />

we're concerned about perceived performance of the application. The users would like an<br />

immediate return of data to the screen, even if it's not the complete result set, and even<br />

if they have to wait longer for the complete result set. This could be a handy way to get<br />

a little bit of information in front of people quickly, so that they can decide whether it's<br />

important and either move on or wait for the rest of the data.<br />

The FAST n hint provides this ability by getting the optimizer to focus on getting the<br />

execution plan to return the first "n" rows as fast as possible, where "n" is a positive<br />

integer value. Consider the following query and execution plan.<br />

SELECT *<br />

FROM Sales.SalesOrderDetail sod<br />

JOIN Sales.SalesOrderHeader soh<br />

ON sod.SalesOrderID = soh.SalesOrderID;<br />

Listing 5.15<br />

Figure 5.11<br />

This query performs adequately considering the fact that it's selecting all the data from<br />

the tables without any sort of filtering operation, but there is a delay before the end-users<br />

see any results, so we can try to fix this by adding the FAST N hint to return the first 10<br />

rows as quickly as possible.<br />

190

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

Saved successfully!

Ooh no, something went wrong!