分区表 主键全局索引和分区索引区别

SQL> create table pdba (agmt_id number,corp_org char(10),agmt_mod_cd char(10),a1 number,a2 number,a3 number,a4 number, start_date date) partition by range (start_date )
(
partition p1 values less than (to_date('2010-10-1', 'yyyy-mm-dd')),
partition p2 values less than (to_date('2010-11-1', 'yyyy-mm-dd')),
partition p3 values less than (to_date('2010-12-1', 'yyyy-mm-dd')),
partition p4 values less than (maxvalue)
)
  2    3    4    5    6    7    8  ;

表已创建。

SQL> desc pdba;
 名称                                    是否为空? 类型
 ----------------------------------------- -------- ----------------------------
 AGMT_ID					    NUMBER
 CORP_ORG					    CHAR(10)
 AGMT_MOD_CD					    CHAR(10)
 A1						    NUMBER
 A2						    NUMBER
 A3						    NUMBER
 A4						    NUMBER
 START_DATE					    DATE



主键为分区索引:

alter table pdba add primary key (AGMT_ID, CORP_ORG, AGMT_MOD_CD) USING INDEX LOCAL;


SQL> alter table pdba add primary key (AGMT_ID, CORP_ORG, AGMT_MOD_CD) USING INDEX LOCAL;
alter table pdba add primary key (AGMT_ID, CORP_ORG, AGMT_MOD_CD) USING INDEX LOCAL
*
第 1 行出现错误:
ORA-14039: 分区列必须构成 UNIQUE 索引的关键字列子集

alter table pdba add primary key (AGMT_ID, CORP_ORG, AGMT_MOD_CD, start_date ) USING INDEX LOCAL;

必须把分区列 加入到主键

SQL> alter table pdba add primary key (AGMT_ID, CORP_ORG, AGMT_MOD_CD, start_date ) USING INDEX LOCAL;

表已更改。
SQL>  select index_name,table_name,PARTITIONED,GLOBAL_STATS from dba_indexes where table_name='PDBA';

INDEX_NAME		       TABLE_NAME		      PAR GLO
------------------------------ ------------------------------ --- ---
SYS_C0023490		       PDBA			      YES NO


如果主键是全局索引呢?
alter table pdba add primary key (AGMT_ID, CORP_ORG, AGMT_MOD_CD);

SQL> alter table pdba add primary key (AGMT_ID, CORP_ORG, AGMT_MOD_CD);

表已更改。

全局的可以

GLOBAL_STATS	VARCHAR2(3)	 	For partitioned indexes, indicates whether statistics were collected by analyzing the index as a whole (YES) or were estimated from 

statistics on underlying index partitions and subpartitions (NO)


对于分区索引,表明是否统计信息是通过分析index 作为整个搜集的 或者 是从依赖的分区或者子分区评估的

PARTITIONED	VARCHAR2(3)	 	Indicates whether the index is partitioned (YES) or not (NO)

SQL> select index_name,table_name,PARTITIONED,GLOBAL_STATS from dba_indexes where table_name='PDBA';

INDEX_NAME		       TABLE_NAME		      PAR GLO
------------------------------ ------------------------------ --- ---
SYS_C0023489		       PDBA			      NO  YES

原文地址:https://www.cnblogs.com/hzcya1995/p/13349941.html