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.

Chapter 7: Special Datatypes and <strong>Execution</strong> <strong>Plans</strong><br />

SELECT e.BusinessEntityID ,<br />

p.LastName<br />

FROM HumanResources.Employee AS e<br />

JOIN Person.Person AS p<br />

ON e.BusinessEntityId = p.BusinessEntityId<br />

WHERE e.OrganizationNode.IsDescendantOf(@ManagerId) = 1<br />

Listing 7.14<br />

This query returns fourteen rows and runs in about 214ms with 48 reads on the<br />

Person.Person table and three on the HumanResources.Employee table.<br />

Figure 7.15 shows the execution plan.<br />

Figure 7.15<br />

As you can see, it's a very simple and clean plan. The optimizer is able to make use of<br />

an index on the HIERARCHYID column, OrganizationNode, in order to perform an<br />

Index Seek. The data then flows out to the Nested Loops operator, which retrieves data<br />

as needed through a series of Clustered Index Seek commands on the Person.Person<br />

table, which results in all the additional reads on that table. The interesting aspect of<br />

this plan is the Seek Predicate of the Index Seek operation, as shown in the ToolTip in<br />

Figure 7.16.<br />

280

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

Saved successfully!

Ooh no, something went wrong!