You are on page 1of 1

li

1234 Chapter 30 Microsoft SQL Server

Ir-

\\

30.3

,.,"olag~ and Indexir.g

1235

The goal of the allocation system is to minirnize the amount of space wasted while, at the sarne time, keeping the amount of fragrnentation in the database to a rninimum to ensure good scan performance. In order to achieve this goal, the allocation manager usually allocates and deallocates all the pages in units of eight contiguous pages called exrents. . The allocation system manages these extents through various bitmaps. These bitmaps allow the allocation system to find a page or an extent for allocation quickly. These bitmaps are ais o used when a full table or index scan is executsd. The advantage of using allocation-based bitmaps for scanning is that it allows disk-order traversals of all the extents belonging to a table or index-Ieaf level, which significantly improves the scan performance. If there is more than one file in a filegroup, the allocation system allocates extents for any object on that filegroup by using a "proportional fill" algorithm. Each file is filled up in the proportion of the amount of free space in that file compared to other files. This fills ali the files in a filegroup at roughly the same rate and allows the system to utilize all the files in the filegroup evenly. Files can also be configured to grow automatically if the filegroup is running out of space. SQLServer allows files to shrink. In order to shrink a data file, SQLServe r moves all the data frorn the physical end of the file to a point eloser to the beginning of the file and then actually shrinks the file, releasing space back to the operating system.
30.3.3 Tables

clustered index contain the key columns of the clustered index. Thus, the clustered index rows can move to a different page (via splts, defragmentation, or even index rebuilds) without requiring changes to the nonelustered indices. SQLServer supports the addition of computed columns to a table. A computed column is a column whose value is an expression, usually based on the value of other columns in that row. SQLServer allows the user to build secondary indices on cornputed columns,
30.3.5 Partitions

SQL Server supports range partitioning on tables and nonclustered ndices. A partitioned index is made up of multiple B+-trees, one per partition. A partitioned table without an index (a heap) is made up of multiple heaps, one per partifion. For brevity, we refer only to partitioned indices (elustered or nonelustered) and ignore heaps for the rest of this discussion. Partitioning a large index allows an administrator more flexibility in managing the storage for the index and can improve some query performance because the partitions act as a coarse-grained index. The partitioning for an index is specified by providing both a partitioning function and a partitioning scheme. A partitioning function maps the domain of a partitioning colurnn (any column in the index) to partitions numbered 1 to N. A partitioning scheme maps partition numbers produced by a partitioning function to specific filegroups where the partitions are stored.
30.3.6 Online Index Build

SQL Server supports heap and clustered organizations for tables. In a heaporganized table, the location of every row of the table is determined entirely by the system and is not specified in any way by the user, The rows of a heap have a fixed identifier known as the row (RIO), and this value never changes unless the file is shrunk and the row is moved. If the row becomes large enough that it cannot fit in the page in which it was originally inserted, the record is moved to a different place but a forwarding stub is left in the original place so that the record can still be found by using its original RIO. In a clustered-index organization for a table, the rows of the table are stored in a B+-tree sorted by the clustering key of the index. The clustered-index key also serves as the unque identifier for each row. The key for a clustered index can be defined to be nonunique, in which case SQL Server adds an additional hidden column to make the key unique. The elustered index also serves as a search structure to identify a row of the table with a particular key or scan a set of rows of the table with keys within a certain range. A elustered index is the most common type of table organization.
30.3.4 Indices

Building new indices and rebuilding existing indices on a table can be performed online, i.e., while select, insert, delete, and update operations are being performed on the table. The creation of a new index happens in three phases. The first phase is simply creating an empty B+-tree for the new index with the catalog showing the new index is available for maintenance operations. That is, the new index must be maintained by all subsequent insert, delete, and update operations, but it is not available for queries. The second phase consists of scanning the table to retrieve the index columns for each row, sorting the rows and inserting them into the new B+-tree. These inserts must be careful to interact with the other rows in the new B+-tree placed there by index maintenance operations from updates on the base table. The scan is a snapshot scan that, without locking, ensures the scan sees the entire table with only the results of committed transactions as of the start of the scan. This is achieved by using the snapshot isolation technique described in Section 30.5.1. The final phase of the index build involves updating the catalog to indica te the index build is complete and the index is available for queries.
30.3.7 Scans and Read-ahead

SQL5erver also supports secondary (nonclustered) B+-tree indices. Queries that refer only to columns that are available through secondary indices are processed by retrieving pages from the leaf levei of the indices without having to retrieve data frorn the clustered index or heap. Nonelustered indices over a table with a

Execution of queries in SQLServer can invol ve a variety of different scan modes on the underlying tables and indices. These inelude ordered versus unordered scans,

You might also like