使用alter table .. merge partition语句将两个分区的内容合并到另外一个分区,两个源分区和关联的local index都会被drop,不能用
merging partitions
使用alter table .. merge partition语句将两个分区的内容合并到另外一个分区,两个源分区和关联的local index都会被drop
不能用于 hash分区表或 hash subpartitions of a composite *-hash partitioned table
不能用于合并引用分区表(reference-partitioned table)
合并范围分区
允许合并两个临近范围的分区到另外分区,不相邻分区无法合并。合并结果分区继承两个源分区的最大边界。
demo:
-- create a table with four partitions each on its own tablespace
-- partitioned by range on the data column.
create table four_seasons
(
one date,
two varchar2(60),
three number
)
partition by range ( one )
(
partition quarter_one
values less than ( to_date('01-apr-1998','dd-mon-yyyy'))
tablespace quarter_one,
partition quarter_two
values less than ( to_date('01-jul-1998','dd-mon-yyyy'))
tablespace quarter_two,
partition quarter_three
values less than ( to_date('01-oct-1998','dd-mon-yyyy'))
tablespace quarter_three,
partition quarter_four
values less than ( to_date('01-jan-1999','dd-mon-yyyy'))
tablespace quarter_four
);
-- create local prefixed index on four_seasons
-- prefixed because the leftmost columns of the index match the
-- partitioning key create index i_four_seasons_l on four_seasons ( one,two )
local (
partition i_quarter_one tablespace i_quarter_one,
partition i_quarter_two tablespace i_quarter_two,
partition i_quarter_three tablespace i_quarter_three,
partition i_quarter_four tablespace i_quarter_four
);
下一步,,合并分区.
-- merge the first two partitions
--
alter table four_seasons
merge partitions quarter_one, quarter_two into partition quarter_two
update indexes;
如果不显式声明 update indexes 语句,就必须给受影响的分区 rebuild the local index.
-- rebuild index for quarter_two, which has been marked unusable
-- because it has not had all of the data from q1 added to it.
-- rebuilding the index will correct this.
--
alter table four_seasons modify partition
quarter_two rebuild unusable local indexes;
合并interval partitions
同range一样,必须两个相邻分区才能合并
合并 list partitions则没有限制