Oracle 创建索引分区
本地索引分区
-- 查看表的分区信息 SELECT INDEX_NAME, PARTITION_NAME, TABLESPACE_NAME FROM DBA_IND_PARTITIONS WHERE TABLESPACE_NAME = 'TABLESPACE_01'; SELECT INDEX_NAME, PARTITION_NAME, TABLESPACE_NAME FROM DBA_IND_PARTITIONS WHERE TABLESPACE_NAME = 'TABLESPACE_02'; -- 创建本地索引分区 CREATE INDEX RANGE_INDEX ON RANGE_TEST (ADD_TIME) LOCAL ( PARTITION TABLE_01 TABLESPACE TABLESPACE_01, PARTITION TABLE_02 TABLESPACE TABLESPACE_02, PARTITION Y2018 TABLESPACE TABLESPACE_01 );
全局索引分区
-- 创建全局索引范围分区 CREATE INDEX RANGE_GLOBAL_INDEX ON RANGE_TEST (ID, ADD_TIME) GLOBAL PARTITION BY RANGE(ID) ( PARTITION TABLE_01 VALUES LESS THAN (1000), PARTITION TABLE_02 VALUES LESS THAN (5000), PARTITION Y2018 VALUES LESS THAN (MAXVALUE) ); -- 创建全局索引的HASH分区(设定为3个分区) CREATE INDEX HASH_GLOBAL_INDEX ON HASH_TEST (ADD_TIME) GLOBAL PARTITION BY HASH(ADD_TIME) PARTITIONS 3;
管理索引分区
-- 删除全局索引,不能删除MAXVALUE分区 ALTER INDEX RANGE_GLOBAL_INDEX DROP PARTITION TABLE_01; ALTER INDEX RANGE_GLOBAL_INDEX REBUILD PARTITION Y2018;