标签:
Aligned Index 是指索引结构的分区和Table的分区相同,即在表的一个分区建立的索引,索引的Leaf Data 也在同一个分区中。
Partition column 是个关键的table column,影响index的对齐。
There are a number of important considerations for creating indexes and constraints on a partitioned table. Table partitioning can work with heap tables without primary keys or indexes, but normally constraints and indexes are required to maintain the integrity of the table data as well as enable important partitioning benefits for management and query performance.
In a partitioned table, the partition column must be a part of:
1,The partition column must be part of the clustered index key.
This makes sense because one of the purposes of a clustered index is to physically organize the pages of a table, and partitioning affects the physical structure of a table as well. SQL Server will internally enforce that the partition column is part of the clustered key, when the table is placed on the partition scheme and the clustered index is created.
2,The partition column must also be part of the primary key of the partitioned table, if one is declared, whether the primary key is clustered or nonclustered.
A primary key has an underlying index to enforce uniqueness. You can place the partitioned column after the original primary key columns. For example, the AdventureWorksDW2008 dbo.FactInternetSales table has a primary key of (SalesOrder, SalesOrderLineNumber). To partition the table on OrderDateKey, just add the partition column to the end of the new primary key: (SalesOrder, SalesOrderLineNumber, OrderDateKey).
3,Any unique index must also have the partition column as part of its key, so that SQL Server can enforce uniqueness across the entire set of partitions.
Therefore any uniqueness constraint must also have the partition column as part of its key. If your unique index or constraint cannot contain the partitioned column, you can enforce the uniqueness using a DML trigger.
For secondary indexes that are not unique or clustered, the requirements are relaxed somewhat. Still, the benefits of including the partition column in a secondary index can be significant. When secondary indexes have the partition column as a part of their key, and use the same or equivalent partition scheme, the indexes are partitioned and are said to be aligned with the underlying object (heap or clustered index).
SQL Server automatically adds the partition column to a secondary nonunique index as an included column if the CREATE INDEX statement does not already contain the partition column.
A secondary index does not have to use the same partition function as the underlying partitioned table to achieve index alignment, as long as the partition function used by each has the same characteristics (equivalent data types of the partition column, number and values of the boundary values, and range direction.) However, it is much more convenient to use the same partition function and partition scheme for the indexes and the underlying partitioned table.
Index alignment helps in achieving partition elimination, where the query processor can eliminate inapplicable partitions from a query plan to access just the partitions required by the query. Index alignment is also required for using the SWITCH statement, which we‘ll cover in the next section. If you have a nonaligned secondary index on a table and need to use the SWITCH option, you can always disable the index during the switch process and re-enable it when done.
If you use the Database Engine Tuning Advisor to recommend indexes, you have the option of choosing a partition strategy. You can have the Database Engine Tuning Advisor recommend indexes with no partitioning, with their own partitioning, or with partitioning aligned with the underlying table.
Note While you can rebuild a partitioned table‘s index with the ONLINE option set to ON, you cannot rebuild a single partition of a partitioned index with the ONLINE set to ON. You must rebuild a single partition or a partitioned index offline because the entire partitioned table will be locked during the rebuild. You can, however, rebuild individual partitions of a partitioned index, but the entire table will be locked.
You can reorganize partitioned indexes and specify individual partitions, lists of partitions, and even ranges of partitions. Reorganizing an index is always an online operation.
标签:
原文地址:http://www.cnblogs.com/ljhdo/p/5016035.html