ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

12c以上的版本,对表进行在线分区(不使用在线重定义)

2020-01-23 10:44:02  阅读:382  来源: 互联网

标签:对表 12c 在线 LESS PARTITION indexes VALUES SQL THAN


12c开始,对表进行在线分区,可以不使用在线重定义的方法。可以直接使用aleter table modify的方式进行分区。

参考文档:

https://docs.oracle.com/en/database/oracle/oracle-database/12.2/vldbg/evolve-nopartition-table.html#GUID-5FDB7D59-DD05-40E4-8AB4-AF82EA0D0FE5

测试环境 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 the INDEXES 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万+ 他的留言板 关注

标签:对表,12c,在线,LESS,PARTITION,indexes,VALUES,SQL,THAN
来源: https://blog.csdn.net/xxzhaobb/article/details/104074253

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有