看了oracle的文档,还是不明白怎么对一个分区建立索引。 create index log_inx on TEST_INDEX(IP_DST,PORT_DST,STARTIME) local ( partition idx_1 tablespace index1_tbs, partition idx_2 tablespace index2_tbs, partition idx_3 tablespace index3_tbs, partition idx_4 tablespace index4_tbs ); 按照这样的方式建立的就是分区索引吧?但是没有办法指定对那个分区建立索引啊,这个语句应该是把索引自身进行了分区管理吧
语法: Table Index CREATE [UNIQUE|BITMAP] INDEX [schema.]index_name ON [schema.]table_name [tbl_alias] (col [ASC | DESC]) index_clause index_attribsindex_clauses: 分以下两种情况1. Local Index 就是索引信息的存放位置依赖于父表的Partition信息,换句话说创建这样的索引必须保证父表是Partition 1.1 索引信息存放在父表的分区所在的表空间。但是仅可以创建在父表为HashTable或者composite分区表的。 LOCAL STORE IN (tablespace) 1.2 仅可以创建在父表为HashTable或者composite分区表的。并且指定的分区数目要与父表的分区数目要一致 LOCAL STORE IN (tablespace) (PARTITION [partition [LOGGING|NOLOGGING] [TABLESPACE {tablespace|DEFAULT}] [PCTFREE int] [PCTUSED int] [INITRANS int] [MAXTRANS int] [STORAGE storage_clause] [STORE IN {tablespace_name|DEFAULT] [SUBPARTITION [subpartition [TABLESPACE tablespace]]]])
1.3 索引信息存放在父表的分区所在的表空间,这种语法最简单,也是最常用的分区索引创建方式。 Local 1.4 并且指定的Partition 数目要与父表的Partition要一致 LOCAL (PARTITION [partition [LOGGING|NOLOGGING] [TABLESPACE {tablespace|DEFAULT}] [PCTFREE int] [PCTUSED int] [INITRANS int] [MAXTRANS int] [STORAGE storage_clause] [STORE IN {tablespace_name|DEFAULT] [SUBPARTITION [subpartition [TABLESPACE tablespace]]]])Global Index 索引信息的存放位置与父表的Partition信息完全不相干。甚至父表是不是分区表都无所谓的。语法如下: GLOBAL PARTITION BY RANGE (col_list) ( PARTITION partition VALUES LESS THAN (value_list) [LOGGING|NOLOGGING] [TABLESPACE {tablespace|DEFAULT}] [PCTFREE int] [PCTUSED int] [INITRANS int] [MAXTRANS int] [STORAGE storage_clause] ) 但是在这种情况下,如果父表是分区表,要删除父表的一个分区都必须要更新Global Index ,否则索引信息不正确 ALTER TABLE TableName DROP PARTITION PartitionName Update Global Indexes
create index log_inx on TEST_INDEX(IP_DST,PORT_DST,STARTIME)
local
(
partition idx_1 tablespace index1_tbs,
partition idx_2 tablespace index2_tbs,
partition idx_3 tablespace index3_tbs,
partition idx_4 tablespace index4_tbs
); 按照这样的方式建立的就是分区索引吧?但是没有办法指定对那个分区建立索引啊,这个语句应该是把索引自身进行了分区管理吧
Table Index
CREATE [UNIQUE|BITMAP] INDEX [schema.]index_name
ON [schema.]table_name [tbl_alias]
(col [ASC | DESC]) index_clause index_attribsindex_clauses:
分以下两种情况1. Local Index
就是索引信息的存放位置依赖于父表的Partition信息,换句话说创建这样的索引必须保证父表是Partition
1.1 索引信息存放在父表的分区所在的表空间。但是仅可以创建在父表为HashTable或者composite分区表的。
LOCAL STORE IN (tablespace)
1.2 仅可以创建在父表为HashTable或者composite分区表的。并且指定的分区数目要与父表的分区数目要一致
LOCAL STORE IN (tablespace) (PARTITION [partition [LOGGING|NOLOGGING] [TABLESPACE {tablespace|DEFAULT}] [PCTFREE int] [PCTUSED int] [INITRANS int] [MAXTRANS int] [STORAGE storage_clause] [STORE IN {tablespace_name|DEFAULT] [SUBPARTITION [subpartition [TABLESPACE tablespace]]]])
1.3 索引信息存放在父表的分区所在的表空间,这种语法最简单,也是最常用的分区索引创建方式。
Local
1.4 并且指定的Partition 数目要与父表的Partition要一致
LOCAL (PARTITION [partition
[LOGGING|NOLOGGING]
[TABLESPACE {tablespace|DEFAULT}]
[PCTFREE int]
[PCTUSED int]
[INITRANS int]
[MAXTRANS int]
[STORAGE storage_clause]
[STORE IN {tablespace_name|DEFAULT]
[SUBPARTITION [subpartition [TABLESPACE tablespace]]]])Global Index
索引信息的存放位置与父表的Partition信息完全不相干。甚至父表是不是分区表都无所谓的。语法如下:
GLOBAL PARTITION BY RANGE (col_list)
( PARTITION partition VALUES LESS THAN (value_list)
[LOGGING|NOLOGGING]
[TABLESPACE {tablespace|DEFAULT}]
[PCTFREE int]
[PCTUSED int]
[INITRANS int]
[MAXTRANS int]
[STORAGE storage_clause] )
但是在这种情况下,如果父表是分区表,要删除父表的一个分区都必须要更新Global Index ,否则索引信息不正确
ALTER TABLE TableName DROP PARTITION PartitionName Update Global Indexes
我的意思是现在有一个分区表,假设里面有分区A,B,C,D,我只需要对A分区做索引,B,C,D分区都不用做索引。因为有索引的时候插入速度太慢,我需要把数据都插入完成以后再建立索引。