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.

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

But the overhead doesn’t stop there. Since we’re in a tree arrangement, you have the possibility for<br />

something of a cascading action. When you create the new page (because of the split), you need to make<br />

another entry in the parent node. This entry in the parent node also has the potential to cause a page<br />

split at that level, and the process starts all over again. Indeed, this possibility extends all the way up to<br />

and can even affect the root node.<br />

If the root node splits, then you actually end up creating two additional pages. Because there can be only<br />

one root node, the page that was formerly the root node is split into two pages and becomes a new intermediate<br />

level of the tree. An entirely new root node is then created, and will have two entries (one to the<br />

old root node, one to the split page).<br />

Needless to say, page splits can have a very negative impact on system performance and are characterized<br />

by behavior where your process on the server seems to just pause for a few seconds (while the<br />

pages are being split and rewritten).<br />

We will talk about page-split prevention before we’re done with this chapter.<br />

While page splits at the leaf level are a common fact of life, page splits at intermediate nodes happen far<br />

less frequently. As your table grows, every layer of the index will experience page splits, but because the<br />

intermediate nodes have only one entry for several entries on the next lower node, the number of page<br />

splits gets less and less frequent as you move further up the tree. Still, for a split to occur above the leaf<br />

level, there must have already been a split at the next lowest level — this means that page splits up the<br />

tree are cumulative (and expensive performance-wise) in nature.<br />

<strong>SQL</strong> <strong>Server</strong> has a number of different types of indexes (which we will discuss shortly), but they all make<br />

use of this B-Tree approach in some way or another. Indeed, they are all very similar in structure, thanks<br />

to the flexible nature of a B-Tree. Still, we shall see that there are indeed some significant differences, and<br />

these can have an impact on the performance of our system.<br />

For an <strong>SQL</strong> <strong>Server</strong> index, the nodes of the tree come in the form of pages, but you can actually apply this<br />

concept of a root node, the non-leaf level, the leaf level, and the tree structure to more than just <strong>SQL</strong><br />

<strong>Server</strong> or even just databases.<br />

How Data Is Accessed in <strong>SQL</strong> <strong>Server</strong><br />

In the broadest sense, there are only two ways in which <strong>SQL</strong> <strong>Server</strong> retrieves the data you request:<br />

❑ Using a table scan<br />

❑ Using an index<br />

Which method <strong>SQL</strong> <strong>Server</strong> uses to run your particular query will depend on what indexes are available,<br />

what columns you are asking about, what kind of joins you are doing, and the size of your tables.<br />

Use of Table Scans<br />

268<br />

A table scan is a pretty straightforward process. When a table scan is performed, <strong>SQL</strong> <strong>Server</strong> starts at the<br />

physical beginning of the table, looking through every row in the table. As it finds rows that match the<br />

criteria of your query, it includes them in the result set.

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

Saved successfully!

Ooh no, something went wrong!