17.06.2013 Views

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

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.

there was no link between the data. With the clustered index, it knows that’s the physical sort, and can<br />

therefore grab it all in just one visit to the page.<br />

Just to be fair to the non-clustered index on a heap here vs. the clustered index, the odds are extremely<br />

high that any page that was already read once will still be in the memory cache and, as such, will be<br />

retrieved extremely quickly. Still, it does add some additional logical operations to retrieve the data.<br />

Figure 9-6 shows the same search we performed on the clustered index, only with a non-clustered index<br />

on a heap this time.<br />

Through most of the index navigation, things work exactly as they did before. We start out at the same<br />

root node, and we traverse the tree dealing with more and more focused pages until we get to the leaf<br />

level of our index. This is where we run into the difference. With a clustered index, we could have<br />

stopped right here, but with a non-clustered index, we have more work to do. If the non-clustered index<br />

is on a heap, then we have just one more level to go. We take the Row ID from the leaf level page and<br />

navigate to it. It is not until this point that we are at our actual data.<br />

Root<br />

Non-Leaf<br />

Level<br />

Leaf Level<br />

Data Pages<br />

Figure 9-6<br />

1<br />

2<br />

52<br />

476405<br />

236205<br />

111903<br />

Chapter 9: <strong>SQL</strong> <strong>Server</strong> Storage and Index Structures<br />

53<br />

54<br />

103<br />

1<br />

53<br />

104<br />

100403<br />

236201<br />

241905<br />

104<br />

105<br />

156<br />

220701<br />

220702<br />

220703<br />

220704<br />

220701<br />

334205<br />

141604<br />

020001<br />

Ralph<br />

Ashley<br />

Bill<br />

Non-Clustered Indexes on a Clustered Table<br />

Looking for Records<br />

158 through 400<br />

With non-clustered indexes on a clustered table, the similarities continue — but so do the differences. Just<br />

as with non-clustered indexes on a heap, the non-leaf level of the index looks pretty much as it did for a<br />

clustered index. The difference does not come until we get to the leaf level.<br />

1<br />

157<br />

157<br />

158<br />

269<br />

141602<br />

220702<br />

220701<br />

241901<br />

241902<br />

241903<br />

241904<br />

241905<br />

270<br />

271<br />

400<br />

401<br />

Bob<br />

Sue<br />

Tony<br />

George<br />

157<br />

270<br />

410<br />

220703<br />

236204<br />

127504<br />

126003<br />

411<br />

412<br />

236201<br />

236202<br />

236203<br />

236204<br />

236205<br />

151501<br />

102404<br />

Nick<br />

Don<br />

Kate<br />

Tony<br />

Francis<br />

273

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

Saved successfully!

Ooh no, something went wrong!