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.

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

We will be looking into locking extensively in Chapter 14, but we will see the lockability of objects<br />

within <strong>SQL</strong> <strong>Server</strong> discussed in passing as we look at storage.<br />

The Extent<br />

An extent is the basic unit of storage used to allocate space for tables and indexes. It is made up of eight<br />

contiguous 64KB data pages.<br />

The concept of allocating space based on extents, rather than actual space used, can be somewhat difficult<br />

to understand for people used to operating system storage principles. The important points about<br />

an extent include:<br />

❑ Once an extent is full, the next record will take up not just the size of the record, but the size of a<br />

whole new extent. Many people who are new to <strong>SQL</strong> <strong>Server</strong> get tripped up in their space estimations<br />

in part due to the allocation of an extent at a time rather than a record at a time.<br />

❑ By pre-allocating this space, <strong>SQL</strong> <strong>Server</strong> saves the time of allocating new space with each record.<br />

It may seem like a waste that a whole extent is taken up just because one too many rows were added to<br />

fit on the currently allocated extent(s), but the amount of space wasted this way is typically not that<br />

much. Still, it can add up — particularly in a highly fragmented environment — so it’s definitely something<br />

you should keep in mind.<br />

The good news in taking up all this space is that <strong>SQL</strong> <strong>Server</strong> skips some of the allocation-time overhead.<br />

Instead of worrying about allocation issues every time it writes a row, <strong>SQL</strong> <strong>Server</strong> deals with additional<br />

space allocation only when a new extent is needed.<br />

Don’t confuse the space that an extent is taking up with the space that a database takes up. Whatever<br />

space is allocated to the database is what you’ll see disappear from your disk drive’s available-space number.<br />

An extent is merely how things are, in turn, allocated within the total space reserved by the database.<br />

The Page<br />

262<br />

Much like an extent is a unit of allocation within the database, a page is the unit of allocation within a<br />

specific extent. There are eight pages to every extent.<br />

A page is the last level you reach before you are at the actual data row. Whereas the number of pages per<br />

extent is fixed, the number of rows per page is not — that depends entirely on the size of the row, which<br />

can vary. You can think of a page as being something of a container for both table- and index-row data.<br />

A row is, in general, not allowed to be split between pages.<br />

There are a number of different page types. For purposes of this book, the types we care about are:<br />

❑ Data — Data pages are pretty self-explanatory. They are the actual data in your table, with the<br />

exception of any BLOB data that is not defined with the text-in-row option, varchar(max) or<br />

varbinary(max).<br />

❑ Index — Index pages are also pretty straightforward: They hold both the non-leaf and leaf level<br />

pages (we’ll examine what these are later in the chapter) of a non-clustered index, as well as the<br />

non-leaf level pages of a clustered index. These index types will become much clearer as we<br />

continue through this chapter.

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

Saved successfully!

Ooh no, something went wrong!