Oracle 12c 新特性 --- 间隔分区

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/leo__1990/article/details/90051043

概念

 

This feature enables reference-partitioned table to use interval partitioning as a top partitioning strategy, which provides a better partitioning modeling. Interval partitioned tables can be used as parent tables for reference partitioning. Partitions in the reference partitioned table corresponding to interval partitions in the parent table are created upon insert into the reference partitioned table.

这个特性允许引用分区表将间隔分区作为顶级分区策略,这提供了更好的分区建模。间隔分区表可以用作引用分区的父表。在插入到引用分区表时, 创建引用分区表中与父表中的间隔分区相对应的分区。

You can use interval partitioned tables as parent tables for reference partitioning. Partitions in a reference-partitioned table corresponding to interval partitions in the parent table are created when inserting records into the reference partitioned table.

When creating an interval partition in a child table, the partition name is inherited from the associated parent table fragment. If the child table has a table-level default tablespace, then it is used as tablespace for the new interval partition; otherwise, the tablespace is inherited from the parent table fragment.

The SQL ALTER TABLE SET INTERVAL statement is not allowed for reference-partitioned tables, but can be run on tables that have reference-partitioned children. In particular, ALTER TABLE SET INTERVAL removes the interval property from the targeted table and converts any interval-reference children to ordinary reference-partitioned tables. Also, the SQL ALTER TABLE SET STORE IN statement is not allowed for reference-partitioned tables, but can be run on tables that have reference-partitioned children.

Operations that transform interval partitions to conventional partitions in the parent table, such as ALTER TABLE SPLIT PARTITION on an interval partition, construct the corresponding transformation in the child table, creating partitions in the child table as necessary.

可以使用间隔分区表作为引用分区的父表。当将记录插入到引用分区表时,创建与父表中间隔分区对应的引用分区表中的分区。

当在子表中创建间隔分区时,分区名是从相关的父表片段继承而来的。如果子表具有表级的默认表空间,那么它就被用作新的间隔分区的表空间;否则,表空间是从父表片段继承的。

SQL ALTER TABLE SET INTERVAL语句不允许使用引用分区表,但是可以在有引用分区的子表的表上运行。特别是,ALTER TABLE SET INTERVAL从目标表中删除间隔属性,并将任何interval- reference children转换为普通的引用分区表。此外,语句中的SQL ALTER TABLE集合存储不允许用于引用分区表,但是可以在具有引用分区子的表上运行。

将间隔分区转换到父表中的常规分区的操作,例如在一个间隔分区上改变表分割分区,在子表中构造相应的转换,必要时在子表中创建分区。

实验 

1) 创建间隔分区表
[oracle@host1 ~]$ sqlplus test/test@pdbcndba

SQL*Plus: Release 12.1.0.2.0 Production on Sun Aug 6 18:03:02 2017

Copyright (c) 1982, 2014, Oracle.  All rights reserved.

Last Successful login time: Sun Aug 06 2017 17:34:22 +08:00

Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL> CREATE TABLE par(pk INT CONSTRAINT par_pk PRIMARY KEY, i INT)
 PARTITION BY RANGE(i) INTERVAL (10)
 (PARTITION p1 VALUES LESS THAN (10));

Table created.
2)创建分区表的子表,并在主表分区表中插入数据
SQL> CREATE TABLE chi(fk INT NOT NULL, i INT,
 CONSTRAINT chi_fk FOREIGN KEY(fk) REFERENCES par(pk))
 PARTITION BY REFERENCE(chi_fk); 

Table created.

SQL> INSERT INTO par VALUES(15, 15);

1 row created.

SQL> INSERT INTO par VALUES(25, 25);

1 row created.

SQL> INSERT INTO par VALUES(35, 35);

1 row created.

SQL> INSERT INTO chi VALUES(15, 15);

1 row created.

3)通过视图USER_TAB_PARTITIONS,可以看到分区信息,如果同时在子表插入数据,子表会自动创建分区,分区名从父表继承而来。

SQL> col table_name for a10;
SQL> col PARTITION_NAME for a20
SQL> col interval for a10

SQL> set lines 200
SQL> SELECT table_name,partition_name, partition_position, high_value, interval
   FROM USER_TAB_PARTITIONS WHERE table_name IN ('PAR', 'CHI')
   ORDER BY 1, 2;

TABLE_NAME PARTITION_NAME	PARTITION_POSITION HIGH_VALUE		       INTERVAL
---------- -------------------- ------------------ --------------------------- ----------
CHI	       P1		                1			        NO
CHI	       SYS_P324	                        2			        YES
PAR	       P1				1 10			        NO
PAR	       SYS_P324				2 20		                YES
PAR	       SYS_P325				3 30			        YES
PAR	       SYS_P326				4 40			        YES


4)如果在父表中分割了间隔分区,那么一些间隔分区将转换为层次结构中的所有表的常规分区,在进程的子表中创建常规分区。
SQL> ALTER TABLE par SPLIT PARTITION FOR (25) AT (25)
   INTO (partition x, partition y);

Table altered.

SQL> SELECT table_name,partition_name, partition_position, high_value, interval
   FROM USER_TAB_PARTITIONS WHERE table_name IN ('PAR', 'CHI')
   ORDER BY 1, 2; 

TABLE_NAME PARTITION_NAME	PARTITION_POSITION HIGH_VALUE		      INTERVAL
---------- -------------------- ------------------ -------------------------- ----------
CHI	       P1		                1				NO
CHI	       SYS_P324				2				NO
CHI	       X			        3				NO
CHI	       Y			        4				NO
PAR	       P1			        1 10				NO
PAR	       SYS_P324			        2 20				NO
PAR	       SYS_P326			        5 40				YES
PAR	       X			        3 25				NO
PAR	       Y			        4 30				NO

Interval-reference功能要求设置数据库兼容性级别(Oracle数据库兼容初始化参数设置)设置为大于或等于12.0.0.0。

参考文档

http://docs.oracle.com/database/122/VLDBG/partition-create-tables-indexes.htm#VLDBG14226

猜你喜欢

转载自blog.csdn.net/leo__1990/article/details/90051043
今日推荐