分区表的 Aligned Index

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:

  • The clustered index key.
  • The primary key.
  • Unique index and uniqueness constraint keys.

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.

时间: 2024-07-29 19:53:56

分区表的 Aligned Index的相关文章

在分区表上创建Unique Index

在创建FullText Index之前,指定的Table上必须存在一个只包含Single column的 unique index.如果在分区表上创建的Unique Index 不包括Partition Column,SQL Server 抛出Error Message,脚本如下 CREATE UNIQUE NONCLUSTERED INDEX UQ_IDX_IndexName ON Schema_Name.table_name ( [col1] ) with(data_compression=

分区表的索引

分区表的索引分为:分区对齐索引(Aligned Index)和非对齐索引.对齐索引是指索引结构的分区和基础表的分区相同,这意味着,在表的一个分区上创建的索引,索引结构也在同一个分区中.索引结构在每个分区中都是独立存储和维护的,如果索引结构和表结构在同一个分区(也就是在同一个文件组上),那么索引是与基础表对齐的索引.创建对齐索引,并不意味着必须使用相同名称的分区scheme,只要分区schem使用的分区边界和每个分区存储的文件组相同,这两个分区schem是等价的,使用等价的分区scheme创建的索

Oracle笔记 五、创建表、约束、视图、索引、序列、同义词、表空间

alter table userInfo add(msn varchar2(20));   1.建表 create table userInfo ( id number(6), name varchar2(20), sex number(1), age number(3), birthday date, address varchar2(50), email varchar2(25), tel number(11) );   2.创建约束 不带约束名称的: create table userIn

oracle 性能优化--索引总结

索引是建立在表的一列或多个列上的辅助对象,目的是加快訪问表中的数据: Oracle存储索引的数据结构是B*树.位图索引也是如此,仅仅只是是叶子节点不同B*数索引: 索引由根节点.分支节点和叶子节点组成.上级索引块包括下级索引块的索引数据,叶节点包括索引数据和确定行实际位置的rowid. 使用索引的目的: 加快查询速度 降低I/O操作 消除磁盘排序 何时使用索引: 查询返回的记录数 排序表<40% 非排序表 <7% 表的碎片较多(频繁添加.删除) 索引的种类 非唯一索引(最经常使用) 唯一索引

Oracle的rowid

ROWID是数据的详细地址,通过rowid,oracle可以快速的定位某行具体的数据的位置. ROWID可以分为物理rowid和逻辑rowid两种.普通的堆表中的rowid是物理rowid,索引组织表(IOT)的rowid是逻辑rowid.oracle提供了一种urowid的数据类型,同时支持物理和逻辑rowid.本文主要关注物理rowid 物理rowid又分为扩展rowid(extended rowid)和限制rowid(restricted rowid)两种格式.限制rowid主要是orac

oracle rowid 使用

ROWID是数据的详细地址,通过rowid,oracle可以快速的定位某行具体的数据的位置. ROWID可以分为物理rowid和逻辑rowid两种.普通的堆表中的rowid是物理rowid,索引组织表(IOT)的rowid是逻辑rowid.oracle提供了一种urowid的数据类型,同时支持物理和逻辑rowid.本文主要关注物理rowid 物理rowid又分为扩展rowid(extended rowid)和限制rowid(restricted rowid)两种格式.限制rowid主要是orac

oracle建表的时候同时创建主键,外键,注释,约束,索引

--主键create table emp (id number constraint id_pr primary key ,name1 varchar(8));create table emp9 (id number ,name1 varchar(8) ,constraint aba_pr primary key(id,name1));--外键create table emp1(id number references emp(id),name varchar(8)); --复合外键create

Oracle ORA-08104报错处理方法及注意事项

[环境介绍] 系统环境:IBM P740 8205-E6C (AIX) + 11.2.0.3.0 Oracle RAC [背景介绍] 故障描述:数据库表空间超过90%,无法进行扩容表空间,需要业务侧清理历史数据,在清理期间出现ORA-08104报错,无法再进行清理数据. 反馈报错信息: 从数据库报错看出,有会话执行了重建索引操作或者重建索引操作时回退. [问题分析] 查看数据库日志信息:发现数据库报错,出现临时表空间不足情况,查看当前表为分区表,大小为180多G,怀疑重建索引时临时表空间不足导致

MySQL分区表姿势

大部分内容整理自姜承尧的innodb存储引擎2学习笔记. 分区: 分区的功能不是在存储引擎层实现的.因此不只是InnoDB才支持分区.MyISAM.NDB都支持分区操作. 分区的过程是将一个表或者索引分解为多个更小.更可管理的部分.从逻辑上将,只有一个表或者索引,但是在物理上这个表或索引可能由数十个物理分区组成. 每个分区都是独立的对象,可以独自处理,也可以作为一个更大对象的一部分进行处理. MySQL只支持水平分区,不支持垂直分区. 水平分区:将同一表中不同行的记录分配到不同的物理文件中. 垂