ORA-14039: partitioning columns must form a subset of key columns of a UNIQUE index SYS

来源:互联网 发布:网络骗局大全微信 编辑:程序博客网 时间:2024/06/05 02:27
 ORA-14039 2007-09-21 11:08:52

分类: Oracle

昨天在建一分区表时抛了异常“ORA-14039: 分区列必须构成 UNIQUE 索引的关键字列子集”,具体过程如下:

[@more@]

SQL> begin
2 execute immediate
3 'create table MSG_STORAGE_CACHE
4 (
5 NAME VARCHAR2(64) not null,
6 HASHKEY VARCHAR2(100) not null,
7 PACKAGE VARCHAR2(3000) not null,
8 CREATEDATE DATE default SYSDATE
9 )
10 partition by range(CREATEDATE)
11 (
12 partition p_'||to_char(sysdate-6,'yyyymmdd')||' values less than(to_date('''||to_char(sysdate-5,'yyyymmdd')||''',''yyyymmdd'')),
13 partition p_'||to_char(sysdate-5,'yyyymmdd')||' values less than(to_date('''||to_char(sysdate-4,'yyyymmdd')||''',''yyyymmdd'')),
14 partition p_'||to_char(sysdate-4,'yyyymmdd')||' values less than(to_date('''||to_char(sysdate-3,'yyyymmdd')||''',''yyyymmdd'')),
15 partition p_'||to_char(sysdate-3,'yyyymmdd')||' values less than(to_date('''||to_char(sysdate-2,'yyyymmdd')||''',''yyyymmdd'')),
16 partition p_'||to_char(sysdate-2,'yyyymmdd')||' values less than(to_date('''||to_char(sysdate-1,'yyyymmdd')||''',''yyyymmdd'')),
17 partition p_'||to_char(sysdate-1,'yyyymmdd')||' values less than(to_date('''||to_char(sysdate,'yyyymmdd')||''',''yyyymmdd'')),
18 partition p_'||to_char(sysdate,'yyyymmdd')||' values less than(to_date('''||to_char(sysdate+1,'yyyymmdd')||''',''yyyymmdd''))
19 )';
20 end;
21 /

PL/SQL procedure successfully completed

SQL> 
SQL> alter table MSG_STORAGE_CACHE
2 add constraint PK_MSG_STORAGE_CACHE primary key(HASHKEY,NAME) using index local;

alter table MSG_STORAGE_CACHE
add constraint PK_MSG_STORAGE_CACHE primary key(HASHKEY,NAME) using index local

ORA-14039: 分区列必须构成 UNIQUE 索引的关键字列子集

SQL>

原来oracle不支持在分区表上创建PK主键时主键列不包含分区列,创建另外的约束(unique)也不可以。

为了解决这个问题,两种方法:1、将CREATEDATE 列也加上pk列中,采用alter table MSG_STORAGE_CACHE
add constraint PK_MSG_STORAGE_CACHE primary key(HASHKEY,NAME,CREATEDATE) using index local;

2、创建index好了create index indx_MSG_STORAGE_CACHE on MSG_STORAGE_CACHE(HASHKEY,NAME) local;

0 0