12c开始,对表进行在线分区,可以不使用在线重定义的方法。可以直接使用aleter table modify的方式进行分区。
参考文档:
测试环境 RDBMS 19.6.0.0
-- 创建测试用的表
SQL> create table employees_convert as select * from hr.employees;
Table created.
SQL>
-- 对测试的表进行转换 (在sys下不支持这样做 )
ALTER TABLE employees_convert MODIFY
PARTITION BY RANGE (employee_id) INTERVAL (100)
( PARTITION P1 VALUES LESS THAN (150),
PARTITION P2 VALUES LESS THAN (200)
) ONLINE
UPDATE INDEXES
( IDX1_SALARY LOCAL,
IDX2_EMP_ID GLOBAL PARTITION BY RANGE (employee_id)
( PARTITION IP1 VALUES LESS THAN (MAXVALUE))
);
SQL> ALTER TABLE employees_convert MODIFY
PARTITION BY RANGE (employee_id) INTERVAL (100)
( PARTITION P1 VALUES LESS THAN (150),
PARTITION P2 VALUES LESS THAN (200)
) ONLINE
2 3 4 5 6 UPDATE INDEXES
( IDX1_SALARY LOCAL,
IDX2_EMP_ID GLOBAL PARTITION BY RANGE (employee_id)
( PARTITION IP1 VALUES LESS THAN (MAXVALUE))
); 7 8 9 10
ALTER TABLE employees_convert MODIFY
*
ERROR at line 1:
ORA-14809: schema does not support ONLINE MODIFY PARTITION BY DDL
SQL>
-- 换其他schema做
SQL> conn hr/oracle
Connected.
SQL> create table employees_convert as select * from hr.employees;
Table created.
SQL> ALTER TABLE employees_convert MODIFY
PARTITION BY RANGE (employee_id) INTERVAL (100)
( PARTITION P1 VALUES LESS THAN (150),
2 3 4 PARTITION P2 VALUES LESS THAN (200)
) ONLINE
5 6 UPDATE INDEXES
7 ( IDX1_SALARY LOCAL,
IDX2_EMP_ID GLOBAL PARTITION BY RANGE (employee_id)
( PARTITION IP1 VALUES LESS THAN (MAXVALUE))
); 8 9 10
( IDX1_SALARY LOCAL,
*
ERROR at line 7:
ORA-01418: specified index does not exist -- 因为这里要用到索引,新创建的表上没有索引,所以会出错。先不使用索引,等分区后,再手工创建索引。
SQL>
SQL> ALTER TABLE employees_convert MODIFY
PARTITION BY RANGE (employee_id) INTERVAL (100)
( PARTITION P1 VALUES LESS THAN (150),
PARTITION P2 VALUES LESS THAN (200)
) ONLINE 2 3 4 5
6 ;
Table altered.
SQL>
-- 查看分区
SQL> select table_name,partition_name from user_tab_partitions where table_name='EMPLOYEES_CONVERT' ;
TABLE_NAME PARTITION_
-------------------- ----------
EMPLOYEES_CONVERT P1
EMPLOYEES_CONVERT P2
EMPLOYEES_CONVERT SYS_P522
SQL>
关于update index 语句的一些说明
Considerations When Using the UPDATE INDEXES Clause
When using the UPDATE
INDEXES
clause, note the following.
-
This clause can be used to change the partitioning state of indexes and storage properties of the indexes being converted.
-
The specification of the
UPDATE
INDEXES
clause is optional.Indexes are maintained both for the online and offline conversion to a partitioned table.
-
This clause cannot change the columns on which the original list of indexes are defined.
-
This clause cannot change the uniqueness property of the index or any other index property.
-
If you do not specify the tablespace for any of the indexes, then the following tablespace defaults apply.
-
Local indexes after the conversion collocate with the table partition.
-
Global indexes after the conversion reside in the same tablespace of the original global index on the non-partitioned table.
-
-
If you do not specify the
INDEXES
clause or theINDEXES
clause does not specify all the indexes on the original non-partitioned table, then the following default behavior applies for all unspecified indexes.-
Global partitioned indexes remain the same and retain the original partitioning shape.
-
Non-prefixed indexes become global nonpartitioned indexes.
-
Prefixed indexes are converted to local partitioned indexes.
Prefixed means that the partition key columns are included in the index definition, but the index definition is not limited to including the partitioning keys only.
-
Bitmap indexes become local partitioned indexes, regardless whether they are prefixed or not.
Bitmap indexes must always be local partitioned indexes.
-
-
The conversion operation cannot be performed if there are domain indexes.
END
文档搬运工 发布了756 篇原创文章 · 获赞 32 · 访问量 20万+ 关注