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.

GO<br />

Listing 4.1<br />

Chapter 4: Understanding More Complex Query <strong>Plans</strong><br />

FROM [Sales].[SalesTaxRate] st<br />

JOIN [Person].[StateProvince] sp<br />

ON [st].[StateProvinceID] = [sp].[StateProvinceID]<br />

WHERE [sp].[CountryRegionCode] = @CountryRegionCode<br />

ORDER BY [StateName] ;<br />

Which we can then execute:<br />

EXEC [Sales].[spTaxRateByState] @CountryRegionCode = 'US';<br />

Listing 4.2<br />

The resulting actual execution plan is quite simple, as shown in Figure 4.1.<br />

Figure 4.1<br />

Starting from the right, we see a Clustered Index Scan operator, which gets the list of tax<br />

rates. The query combines this data with data pulled from the States table, based on<br />

the parameter, @CountryRegionCode, visible in the ToolTip or the Properties window,<br />

through a Nested Loops operation.<br />

139

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

Saved successfully!

Ooh no, something went wrong!