Oracle 19c: Hybrid Partition Table
从Oracle Database 19c开始,Oracle数据库支持Hybrid partitioned tables,也就是混合分区表,进一步扩展了Oracle分区技术。这里的混合指的是数据的分布,一些分区可以位于数据库中,另一些可以是位于数据库外部的文件(比如操作系统文件或Hadoop Distributed File System (HDFS) 文件)。这个特性的出现,其实一点也不奇怪,因为从12.2开始就支持了外部表分区、只读分区,在19c中只是将内部分区(internal partitions)与Oracle外部分区(external partitions)特性结合起来,形成一个更通用的分区,称为混合分区表。
Oracle 三大件: DG, RAC, Partition
When to partition a table:
1. table great than 2GB
2. table contains historical data, which new data is added into the newest partition
How to change to partition tables:
1. export/import method
2. insert with a subquery method
3. partition exchange method
4. dbms_redefiniation
Orcle Partition History:
7.3: start, through view
8i: hash partition
9i: 支持列表分区
10g: 支持IoT, 个数由64k to 1024k,全局索引的hash分区
11g: 间隔分区,多种组合分区,虚拟列分区,分区建议器
12c: 在线分区维护,部分分区索引,global索引维护,外部分区表,分区与sharding,只读分区
18c: 在线更改分区类型,在线merge分区,parallel partition wise-join
19c: 混合分区表
--Oracle 11g Interval auto creation
create table intervalpart (c1 number, c3 date)
partition by range(c3)
interval (numtoyminterval(1, "MONTH'))
partition part1
values less than (to_date('01/01/2019','mm/dd/yyyy'));
begin
for 1 in 0.. 11 loop
insert into intervalpart values (1, add_months(to_date('2019-1-1','yyyy-mm-dd').i));
end loop;
commit;
end;
/
set pagesize 1000 linesize 400 lines 380
select * from intervalpart;
select table_name, partition_anme from user-tab_partitions where table_name ='INTERVALPART';
--Oracle 12c
read only partition or read only table (, but some partition can read write)
---online operation partition
create table t_partition_range (idn number, name varchar2(50))
partition by range(id)(
partition t_range_p1 values less than (10),
partition t_range_p1 values less than (20),
partition t_range_p1 values less than (30),
);
insert into t_partition_range values (1, 'aa');
insert into t_partition_range values (2, 'bb');
insert into t_partition_range values (3, 'cc');
commit;
create index t_partition_range_idx on t_partition_range(id);
select index_name, status from user_indexes where table_name ='T_PARTITION_RANGE';
alter table t_partition_range move partition t_range_p3 tablespace testtbs update indexes online;
alter table t_partition_range move partition t_range_p3 row store compress update indexes online;
select index_name, status from user_indexes where table_name ='T_PARTITION_RANGE';
---add multiple at once
alter table t_partition_range add partition t_range_p4 values less than (40),
partition t_range_p5 values less than (50),
partition t_range_p5 values less than (60);
alter table t_partition_range truncate partitions t_range_p4, t_range_p5, t_range_p6;
alter table t_partition_range drop partitions t_range_p4, t_range_p5, t_range_p6;
alter table t_partition_range split partition t_range_p3
(
partition t_range_p3_1 values less than (24),
partition t_range_p3_2 values less than (29),
partition t_range_p3_3
);
alter table t_partition_range merge partitions t_range_p3_1, t_range_p3_2. t_range_p3_3 into partition t_range3;
alter index t_partition_range_idx rebuild;
---Global index
alter table t_partition_range truncate partition t_range_p3 update global indexes;
alter table_t_partition_range drop partition t_range_p3 updae global indexes;
select index_name, status from user_indexes where table_name ='T_PARTITION_RANGE';
---只生效部分分区的索引
create table t_partition_ranges (idn number, name varchar2(50))
indexing off
partition by range(id)(
partition t_range_p1 values less than (10) indexing on,
partition t_range_p1 values less than (20) indexing on,
partition t_range_p1 values less than (30),
);
create index_part_idx on t_partition_rang2(id) local indexing partial;
select index_name, status from user_indexes where table_name ='PART_IDX';
---在线转换为分区表
create table covert1 (id number, description varchar2(50), created_date date,
constraint convert1_pk primary key (id));
create index convert1_create_date_idx on convert1(created_date);
alter table covert1 modify
partition by range (created_date) (
partition t1_part_2015 values less than (to_date('20160101','yyyymmdd')),
partition t1_part_2016 values less than (to_date('20170101','yyyymmdd')),
partition t1_part_2017 values less than (to_date('20180101','yyyymmdd')),
) online
update indexes
(
covert1_pk global,
covert1_pk global,
convert1_create_date_idx local
);
---外部‘分区’表
。。。
Oracle 18c 支持修改表的分区策略,可以在线操作,不影响DML操作
索引作为表修改的一部分进行维护,在修改分区策略是,所有索引列为新分区键前缀的未指定索引将自动转换为局部分区索引;否则,将索引转换为全局索引/但是不支持区域索引(Domain Index), update index 子句不能更改索引列表最初定义的列,索引的唯一性属性或任何其他索引属性。
Oracle 19c 混合分区的现实意义还是比较明显的,首先通过混合分区可以轻松地将内部(驻留在Oracle表空间中--internal partitions)和外部的数据(external partitions)集成到单个分区表中,其次可以方便地将非活跃数据移动到外部文件,在而降低存储成本的同时也更加方便数据交换。
1)混合分区表支持外部分区的所有现有外部表类型:
•ORACLE_DATAPUMP
•ORACLE_LOADER
•ORACLE_HDFS
•ORACLE_HIVE
2)所有外部表参数均适用于混合分区表的外部分区。
3)混合分区表可以跨内部、外部分区使用基于分区的优化技术,典型的比如:静态分区修剪、动态分区修剪、布隆修剪
4)混合分区表支持的操作
(1)当前仅支持创建single-level的range和list分区,其中只有single-level LIST分区支持HIVE
(2)可以使用alter table ...DDLs操作,比如ADD,DROP和RENAME partitions
(3)可以在分区级别修改external partitions的external data sources 位置
(4)可以将既有的内部分区表修改为混合分区表
(5)可以修改现有的location到empty location形成一个空的external partition
(6)可以针对内部分区创建global partial non-unique indexes
(7)可以针对内部分区创建materialized views
(8) 可以创建包含外部分区的materialized views,前提是QUERY_REWRITE_INTEGRITY必须为STALE_TOLERATED模式
(9)DML操作只能针对混合分区表的内部分区
(10) Validatingwith ANALYZE TABLE ... VALIDATE STRUCTURE on internal partitions only on hybridpartitioned tables
(11)Alteringan existing hybrid partitioned table with no external partitions to apartitioned table with internal partitions only
(12)Anexternal partition can be exchanged with an external nonpartitioned table. Alsoan internal partition can be exchanged with an internal nonpartitioned table.
注意:1)不支持存储在外部分区中的数据强制约束,例如不能在混合分区表上强制主键或外键约束。在混合分区表上,只支持RELYDISABLE约束,要使用基于这种约束的优化特性,需要配合会话参数QUERY_REWRITE_INTEGRITY(设置为TRUSTED或STALE_TOLERATED)。
2)在混合分区表级别定义的AutomaticData Optimization (ADO)策略只影响内部分区
◊Hybrid partitioned tables-混合分区表的限制
(1)Restrictionsthat apply to external tables also apply to hybrid partitioned tables unlessexplicitly noted
(2)不支持REFERENCE和SYSTEM分区方法
(3)No uniqueindexes or global unique indexes. Only partial indexes are allowed and uniqueindexes cannot be partial.
(4)Attributeclustering (CLUSTERING clause) is not allowed
(5)DMLoperations only on internal partitions of a hybrid partitioned table (externalpartitions are treated as read-only partitions)
(6)In-memorydefined on the table level only has an effect on internal partitions of thehybrid partitioned table
(7)No columndefault value
(8)Invisiblecolumns are not allowed
(9)TheCELLMEMORY clause is not allowed
(10)SPLIT,MERGE, and MOVE maintenance operations are not allowed on internal partitions
(11)不支持LOB, LONG和ADT类型
(12)只允许RELYconstraints
Source URL: https://enmotech.com/web/detail/1/653/2.html
--End of File--
Comments
Post a Comment