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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Page Splits — A First Look<br />

All of this works quite nicely on the read side of the equation — it’s the insert that gets a little tricky.<br />

Recall that the B in B-Tree stands for balanced. You may also recall that I mentioned that a B-Tree is balanced<br />

because about half the data is on either side every time you run into a branch in the tree. B-Trees<br />

are sometimes referred to as self-balancing because the way new data is added to the tree generally prevents<br />

them from becoming lopsided.<br />

When data is added to the tree, a node will eventually become full and will need to split. Because in <strong>SQL</strong><br />

<strong>Server</strong>, a node equates to a page, this is called a page split, illustrated in Figure 9-3.<br />

When a page split occurs, data is automatically moved around to keep things balanced. The first half of<br />

the data is left on the old page, and the rest of the data is added to a new page — thus you have about a<br />

50-50 split, and your tree remains balanced.<br />

Figure 9-3<br />

If you think about this splitting process a bit, you’ll realize that it adds a substantial amount of overhead<br />

at the time of the split. Instead of inserting just one page, you are:<br />

❑ Creating a new page<br />

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

❑ Migrating rows from the existing page to the new page<br />

❑ Adding your new row to one of the pages<br />

2<br />

4<br />

6<br />

8<br />

2<br />

4<br />

5<br />

6<br />

8<br />

❑ Adding another entry in the parent node<br />

Ordered insert as middle record<br />

in a Cluster Key<br />

×<br />

5<br />

New record to be inserted,<br />

but the page is full.<br />

Since the new record needs to go in the<br />

middle, the page must be split.<br />

267

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

Saved successfully!

Ooh no, something went wrong!