rfusca Asked: 2013-01-11 06:10:15 +0800 CST2013-01-11 06:10:15 +0800 CST 2013-01-11 06:10:15 +0800 CST 将作为主键的分区全局非唯一索引更改为非分区唯一索引 772 我们系统中最大的表之一将其主键设置为全局分区(在巨大的、无用的、数十亿值范围内)非唯一索引。它的值只是一个序列值,它们绝对是唯一的。我想将索引更改为普通的全局(表已分区)唯一索引。 我可以在不删除约束和索引然后重建的情况下做到这一点吗?在此期间表将没有这个重要的索引? oracle index 1 个回答 Voted Best Answer Philᵀᴹ 2013-01-11T07:23:10+08:002013-01-11T07:23:10+08:00 您可以使用 来执行此操作DBMS_REDEFINITION,但您需要将表格占用的空间增加一倍。 如果我正确阅读了您的问题,应该这样做: [oracle@node1 ~]$ sqlplus phil/phil SQL*Plus: Release 11.2.0.2.0 Production on Sun Jan 6 18:47:12 2013 Copyright (c) 1982, 2010, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> set echo on SQL> @part SQL> SQL> drop table PARTITIONED_INTERIM; Table dropped. SQL> SQL> drop table partitioned; Table dropped. SQL> SQL> create table partitioned 2 ( 3 pk number, 4 blah varchar(40), 5 blah2 varchar(40) 6 ) 7 partition by range (pk) 8 (partition p1 values less than (1000), 9 partition p2 values less than (10000), 10 partition p3 values less than (30000), 11 partition p4 values less than (MAXVALUE) 12 ); Table created. SQL> SQL> create index pk_idx 2 on partitioned (pk) 3 global partition by range (pk) 4 (partition p1 values less than (1000), 5 partition p2 values less than (10000), 6 partition p3 values less than (30000), 7 partition p4 values less than (MAXVALUE) 8 ) 9 ; Index created. SQL> SQL> ALTER TABLE partitioned ADD CONSTRAINT ppk PRIMARY KEY (pk) USING INDEX pk_idx; Table altered. SQL> SQL> select index_name, uniqueness , table_name, partitioned 2 from user_indexes 3 where table_name = 'PARTITIONED'; INDEX_NAME UNIQUENES TABLE_NAME PAR ------------------------------ --------- ------------------------------ --- PK_IDX NONUNIQUE PARTITIONED YES SQL> SQL> EXEC dbms_redefinition.can_redef_table('PHIL', 'PARTITIONED'); PL/SQL procedure successfully completed. SQL> SQL> create table PARTITIONED_INTERIM as ( select * from PARTITIONED where 1=0 ); Table created. SQL> SQL> exec DBMS_REDEFINITION.start_redef_table(uname => 'PHIL',orig_table => 'PARTITIONED',int_table => 'PARTITIONED_INTERIM'); PL/SQL procedure successfully completed. SQL> SQL> create unique index partitioned_interim_pk on partitioned_interim (pk) global online; Index created. SQL> SQL> exec dbms_redefinition.sync_interim_table(uname => 'PHIL',orig_table => 'PARTITIONED',int_table => 'PARTITIONED_INTERIM'); PL/SQL procedure successfully completed. SQL> SQL> exec dbms_redefinition.finish_redef_table(uname => 'PHIL',orig_table => 'PARTITIONED',int_table => 'PARTITIONED_INTERIM'); PL/SQL procedure successfully completed. SQL> SQL> select index_name, uniqueness , table_name, partitioned 2 from user_indexes 3 where table_name = 'PARTITIONED'; INDEX_NAME UNIQUENES TABLE_NAME PAR ------------------------------ --------- ------------------------------ --- PARTITIONED_INTERIM_PK UNIQUE PARTITIONED NO SQL> SQL> SQL> 请注意,您还必须使用DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS()and处理其他索引/对象等DBMS_REDEFINITION.REGISTER_DEPENDENT_OBJECT()。
您可以使用 来执行此操作
DBMS_REDEFINITION
,但您需要将表格占用的空间增加一倍。如果我正确阅读了您的问题,应该这样做:
请注意,您还必须使用
DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS()
and处理其他索引/对象等DBMS_REDEFINITION.REGISTER_DEPENDENT_OBJECT()
。