Oracle 分区索引详解

来源:互联网 发布:selina烧伤事件 知乎 编辑:程序博客网 时间:2024/06/03 16:07

Oracle 分区索引详解

语法:

Table Index CREATE [UNIQUE|BITMAP] INDEX [schema.]index_name ON [schema.]table_name [tbl_alias] (col [ASC | DESC]) index_clause index_attribs

index_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 索引信息存放在父表的分区所在的表空间,这种语法最简单,也是最常用的分区索引创建方式。
Local1.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本人没有深究过在什么情况下,哪种方式更有效。但是个人的感觉是简单的就是最好的
=================================


1.查找分区表
 
select table_name from user_tables where partitioned='YES'
 
2.查看你的分区表的定义
set long 1000
select dbms_metadata.get_ddl('TABLE','TABLENAME','USERNAME'FROM dual;
 
3.合并分区表
alter table tablename merge partitions wqdb01,wqdb02 into partition wqdb02;
4.查看分区表的索引
select index_name,tablespace_name,table_name from user_indexes where PARTITIONED='YES' and table_name='TABLENAME';
5.查看分区表的索引的定义
select dbms_metadata.get_ddl('INDEX','INDEX_NAME','USERNAME'FROM dual
6.删除索引
drop index INDEX_NAME
7 删除表空间
drop tablespace wqdb01 including contents and datafiles;
 
这样就不会出现ORA-14404:分区表包含不同表空间中的分区以及
ORA-14405: 分区索引包含不同表空间中的分区 的问题


原创粉丝点击