暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Oracle 12.2 新特性:自动列表分区(Auto-List Partitioning)

原创 eygle 2016-12-08
819

在Oracle Database 12.2 之前,如果使用列表分区,当插入的数据超过了分区列表值设定,则会抛出异常;而如果存在大量的列表值需要定义,则可能需要一一设置。


在12.2引入的新特性中 - Auto-List Partitioning 可以针对新的列表值,进行自动的分区创建,从而减少了维护的复杂性。


在文档中这样描述:



Partitioning: Auto-List Partitioning




The database automatically creates a separate (new) partition for every distinct partition key value of the table.


Auto-list partitioning removes the management burden from the DBAs to manually maintain a list of partitioned tables for a large number of distinct key values that require individual partitions. It also automatically copes with the unplanned partition key values without the need of a DEFAULT partition.



通过以下测试来简单验证一下这个特性的表征,如果是常规的列表分区,在分区缺失时会遇到ORA-14400错误:


SQL> CREATE TABLE enmotech (
2 PartID integer not null,
3 CretTm date not null,
4 PartCD varchar2(2) not null
5 ) partition by list (partcd) (
6 partition pBJ values ('BJ'),
7 partition pCD values ('CD'),
8 partition pGZ values ('GZ'),
9 partition pSH values ('SH')
10 );
Table created.
SQL> insert into enmotech values (1, sysdate, 'KM');
insert into enmotech values (1, sysdate, 'KM')
*
ERROR at line 1:
ORA-14400: inserted partition key does not map to any partition

当设置了automatic关键字之后,分区变更为自动管理:


drop table enmotech purge;
CREATE TABLE enmotech (
PartID integer not null,
CretTm date not null,
PartCD varchar2(2) not null
) partition by list (partcd) automatic (
partition pBJ values ('BJ'),
partition pCD values ('CD'),
partition pGZ values ('GZ'),
partition pSH values ('SH')
);



当插入一条未定义的分区数据时,新的分区被自动创建:


SQL> insert into enmotech values (1, sysdate, 'KM');
1 row created.
SQL> select partition_name from user_tab_partitions
2 where table_name = 'ENMOTECH';
PARTITION_NAME
----------------------------------------------------
PBJ
PCD
PGZ
PSH
SYS_P290

如果这个自动分片的分区名不符合你的命名规则,可以通过DDL语句去修改变更:


SQL> alter table enmotech rename partition SYS_P290 to pKM;
Table altered.
SQL> select partition_name from user_tab_partitions
2 where table_name = 'ENMOTECH';
PARTITION_NAME
---------------------------------------------------
PBJ
PCD
PGZ
PKM
PSH

对于已有的分区定义,可以通过关键字 automatic 和 manual 来进行分区定义的调整:


alter table PEOPLE set partitioning automatic;
alter table PEOPLE set partitioning manual;

这是Oracle Database 12.2 分区特性的众多增强之一。



最后修改时间:2020-06-01 11:30:42
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论