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 6: Cursor Operations<br />

The major difference is evident in how the Fetch Query works, in order to support the<br />

updating of data after the cursor was built. Figure 6.20 shows that portion of the plan in<br />

more detail.<br />

Figure 6.20<br />

Going to the right and top of the Fetch Query definition, we find that it first retrieves the<br />

key from the index created in the Population Query. Then, to retrieve the data, it joins it<br />

through a Nested Loop operation to the Sales.Currency table. This is how the Keyset<br />

cursor manages to get updated data into the set returned while the cursor is active.<br />

The Constant Scan operator scans an internal table of constants; basically, it's just a<br />

place for adding data later in the plan. The data from the Constant Scan feeds into the<br />

Clustered Index Update operator in order to be able to change the data stored inside<br />

the cursor, if necessary. This data is joined to the first set of data through a Nested Loop<br />

operation and finishes with a Compute Scalar, which represents the row number.<br />

Physical operators<br />

When the cursor is executed, we get the plan shown in Figure 6.21.<br />

245

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

Saved successfully!

Ooh no, something went wrong!