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

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

cdn.s3techtraining.com
from cdn.s3techtraining.com More from this publisher
17.06.2013 Views

Figure 9-1 Figure 9-2 1 53 104 Root Non-Leaf Level 534 600 755 1 157 534 157 270 410 157 190 210 230 250 261 Leaf Level 410 430 450 475 510 521 270 310 335 360 380 1 10 20 30 41 104 110 121 130 140 53 65 78 90 98 534 545 557 570 588 755 780 795 825 847 860 600 621 641 680 720 1 2 3 4 5 Root Actual Data 6 7 8 9 10 11 12 13 14 15 1 6 11 16 16 17 18 266 Chapter 9: SQL Server Storage and Index Structures

Page Splits — A First Look All of this works quite nicely on the read side of the equation — it’s the insert that gets a little tricky. Recall that the B in B-Tree stands for balanced. You may also recall that I mentioned that a B-Tree is balanced because about half the data is on either side every time you run into a branch in the tree. B-Trees are sometimes referred to as self-balancing because the way new data is added to the tree generally prevents them from becoming lopsided. When data is added to the tree, a node will eventually become full and will need to split. Because in SQL Server, a node equates to a page, this is called a page split, illustrated in Figure 9-3. When a page split occurs, data is automatically moved around to keep things balanced. The first half of 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 50-50 split, and your tree remains balanced. Figure 9-3 If you think about this splitting process a bit, you’ll realize that it adds a substantial amount of overhead at the time of the split. Instead of inserting just one page, you are: ❑ Creating a new page Chapter 9: SQL Server Storage and Index Structures ❑ Migrating rows from the existing page to the new page ❑ Adding your new row to one of the pages 2 4 6 8 2 4 5 6 8 ❑ Adding another entry in the parent node Ordered insert as middle record in a Cluster Key × 5 New record to be inserted, but the page is full. Since the new record needs to go in the middle, the page must be split. 267

Figure 9-1<br />

Figure 9-2<br />

1<br />

53<br />

104<br />

Root<br />

Non-Leaf<br />

Level<br />

534<br />

600<br />

755<br />

1<br />

157<br />

534<br />

157<br />

270<br />

410<br />

157<br />

190<br />

210<br />

230<br />

250<br />

261<br />

Leaf<br />

Level<br />

410<br />

430<br />

450<br />

475<br />

510<br />

521<br />

270<br />

310<br />

335<br />

360<br />

380<br />

1<br />

10<br />

20<br />

30<br />

41<br />

104<br />

110<br />

121<br />

130<br />

140<br />

53<br />

65<br />

78<br />

90<br />

98<br />

534<br />

545<br />

557<br />

570<br />

588<br />

755<br />

780<br />

795<br />

825<br />

847<br />

860<br />

600<br />

621<br />

641<br />

680<br />

720<br />

1<br />

2<br />

3<br />

4<br />

5<br />

Root<br />

Actual<br />

Data<br />

6<br />

7<br />

8<br />

9<br />

10<br />

11<br />

12<br />

13<br />

14<br />

15<br />

1<br />

6<br />

11<br />

16<br />

16<br />

17<br />

18<br />

266<br />

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

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

Saved successfully!

Ooh no, something went wrong!