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

SELECT pm.Name AS ProductModelName,<br />

p.Name AS ProductName,<br />

SUM(pin.Quantity)<br />

FROM Production.ProductModel pm<br />

JOIN Production.Product p<br />

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

JOIN Production.ProductInventory pin<br />

ON p.ProductID = pin.ProductID<br />

GROUP BY pm.Name,<br />

p.Name ;<br />

Listing 5.35<br />

It results in the execution plan in Figure 5.33.<br />

Figure 5.33<br />

As you can see, an Index Scan operation against the ProductModel database<br />

returns the first stream of data. This is joined against a Clustered Index Scan operation<br />

from the Product table, through a Hash Match join operator. The data from the<br />

ProductInventory table can be retrieved through a Clustered Index Seek and this is<br />

then joined to the other data through a Nested Loops join. Finally, the optimizer builds<br />

the summation information through a Stream Aggregate operator.<br />

If we decided that we thought that getting the Product information a bit quicker might<br />

make a difference in the behavior of the query, we could add the FASTFIRSTROW table<br />

hint to that table.<br />

224

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

Saved successfully!

Ooh no, something went wrong!