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 4: Understanding More Complex Query <strong>Plans</strong><br />

SELECT sp.Name AS StateProvinceName,<br />

cr.Name AS CountryRegionName<br />

FROM Person.StateProvince sp<br />

INNER JOIN Person.CountryRegion cr ON<br />

sp.CountryRegionCode = cr.CountryRegionCode ;<br />

Listing 4.13<br />

However, as the execution plan grows in complexity, this behavior is neither automatic<br />

nor guaranteed. For example, consider the query in Listing 4.14.<br />

SELECT a.City,<br />

v.StateProvinceName,<br />

v.CountryRegionName<br />

FROM Person.Address a<br />

JOIN Person.vStateProvinceCountryRegion v<br />

ON a.StateProvinceID = v.StateProvinceID<br />

WHERE a.AddressID = 22701 ;<br />

Listing 4.14<br />

If you expected to see a join between the indexed view and the Person.Address table,<br />

you would be disappointed.<br />

Figure 4.18<br />

163

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

Saved successfully!

Ooh no, something went wrong!