解释:
首先:分区表primary key 是 disable的,非分区表primary key 是 disable的;
其次:交换分区且包括 including indexes;
然后:再次交换分区包括 including indexes;
SQL> select INDEX_NAME,PARTITION_NAME,STATUS from User_Ind_Partitions where INDEX_name='IND_T_PAR_RANGE';
INDEX_NAME PARTITION_NAME STATUS
------------------ ------------------ ----------------
IND_T_PAR_RANGE P_T_PAR_RANGE_0 USABLE
IND_T_PAR_RANGE P_T_PAR_RANGE_1 USABLE
SQL> drop index ind_t_par_range;
索引已删除。
SQL> alter table t_no_par add constraint ind_t_no_par primary key(time,id) using index;
表已更改。
SQL> alter table t_par_range add constraint ind_t_par_range primary key(time,id) using index local;
表已更改。
SQL> select * from t_no_par;
未选定行
SQL> select * from t_par_range;
TIME ID CITY_ID VALUE1 VALUE2
-------------- ---------- ---------- ---------- --------------------
01-3月 -11 1 10 1 a
01-4月 -11 2 20 2 b
SQL> select constraint_name,constraint_type,status,validated from User_Constraints where constraint_name in ('IND_T_NO_PAR','IND_T_PAR_RANGE');
CONSTRAINT_NAME C STATUS VALIDATED
------------------------------ - -------- -------------
IND_T_PAR_RANGE P ENABLED VALIDATED
IND_T_NO_PAR P ENABLED VALIDATED
SQL> SELECT index_name,index_type,status FROM USER_INDEXES WHERE index_NAME in ('IND_T_NO_PAR');
INDEX_NAME INDEX_TYPE STATUS
------------------------------------------------------------
IND_T_NO_PAR NORMAL VALID
SQL> select INDEX_NAME,PARTITION_NAME,STATUS from User_Ind_Partitions where INDEX_name='IND_T_PAR_RANGE';
INDEX_NAME PARTITION_NAME STATUS
------------------ ------------------ ----------------
IND_T_PAR_RANGE P_T_PAR_RANGE_0 USABLE
IND_T_PAR_RANGE P_T_PAR_RANGE_1 USABLE
SQL>
SQL> alter table t_no_par disable constraint ind_t_no_par keep index;
表已更改。
SQL> alter table t_par_range disable constraint ind_t_par_range keep index;
表已更改。
SQL>
SQL> select INDEX_NAME,PARTITION_NAME,STATUS from User_Ind_Partitions where INDEX_name='IND_T_PAR_RANGE';
INDEX_NAME PARTITION_NAME STATUS
------------------ ------------------ ----------------
IND_T_PAR_RANGE P_T_PAR_RANGE_0 USABLE
IND_T_PAR_RANGE P_T_PAR_RANGE_1 USABLE
SQL> select constraint_name,constraint_type,status,validated from User_Constraints where constraint_name in ('IND_T_NO_PAR','IND_T_PAR_RANGE');
CONSTRAINT_NAME C STATUS VALIDATED
------------------------------ - -------- -------------
IND_T_PAR_RANGE P DISABLED NOT VALIDATED
IND_T_NO_PAR P DISABLED NOT VALIDATED
SQL> SELECT index_name,index_type,status FROM USER_INDEXES WHERE index_NAME in ('IND_T_NO_PAR');
INDEX_NAME INDEX_TYPE STATUS
------------------------------------------------------------
IND_T_NO_PAR NORMAL VALID
SQL> alter table t_par_range exchange partition p_t_par_range_0 with table t_no_par including indexes;
表已更改。
SQL>
SQL> select * from t_no_par;
TIME ID CITY_ID VALUE1 VALUE2
-------------- ---------- ---------- ---------- --------------------
01-3月 -11 1 10 1 a
SQL> select * from t_par_range;
TIME ID CITY_ID VALUE1 VALUE2
-------------- ---------- ---------- ---------- --------------------
01-4月 -11 2 20 2 b
SQL> select constraint_name,constraint_type,status,validated from User_Constraints where constraint_name in ('IND_T_NO_PAR','IND_T_PAR_RANGE');
CONSTRAINT_NAME C STATUS VALIDATED
------------------------------ - -------- -------------
IND_T_PAR_RANGE P DISABLED NOT VALIDATED
IND_T_NO_PAR P DISABLED NOT VALIDATED
SQL> SELECT index_name,index_type,status FROM USER_INDEXES WHERE index_NAME in ('IND_T_NO_PAR');
INDEX_NAME INDEX_TYPE STATUS
------------------------------------------------------------
IND_T_NO_PAR NORMAL VALID
SQL> select INDEX_NAME,PARTITION_NAME,STATUS from User_Ind_Partitions where INDEX_name='IND_T_PAR_RANGE';
INDEX_NAME PARTITION_NAME STATUS
------------------ ------------------ ----------------
IND_T_PAR_RANGE P_T_PAR_RANGE_0 USABLE
IND_T_PAR_RANGE P_T_PAR_RANGE_1 USABLE
SQL> alter table t_par_range exchange partition p_t_par_range_0 with table t_no_par including indexes;
表已更改。
SQL> select * from t_no_par;
未选定行
SQL> select * from t_par_range;
TIME ID CITY_ID VALUE1 VALUE2
-------------- ---------- ---------- ---------- --------------------
01-3月 -11 1 10 1 a
01-4月 -11 2 20 2 b
SQL> select constraint_name,constraint_type,status,validated from User_Constraints where constraint_name in ('IND_T_NO_PAR','IND_T_PAR_RANGE');
CONSTRAINT_NAME C STATUS VALIDATED
------------------------------ - -------- -------------
IND_T_PAR_RANGE P DISABLED NOT VALIDATED
IND_T_NO_PAR P DISABLED NOT VALIDATED
SQL> SELECT index_name,index_type,status FROM USER_INDEXES WHERE index_NAME in ('IND_T_NO_PAR');
INDEX_NAME INDEX_TYPE STATUS
------------------------------------------------------------
IND_T_NO_PAR NORMAL VALID
SQL> select INDEX_NAME,PARTITION_NAME,STATUS from User_Ind_Partitions where INDEX_name='IND_T_PAR_RANGE';
INDEX_NAME PARTITION_NAME STATUS
------------------ ------------------ ----------------
IND_T_PAR_RANGE P_T_PAR_RANGE_0 USABLE
IND_T_PAR_RANGE P_T_PAR_RANGE_1 USABLE来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/10037372/viewspace-689825/ ,如需转载,请注明出处,否则将追究法律责任。