简体   繁体   English

在现有范围右分区表中添加分区左边界

[英]add partition left boundary in an existing range right partitioned table

My partition function creates right range type partitions. 我的分区功能创建正确的范围类型分区。 It turns out after the data migration that in partition_number one there are boundary values that are lesser than the boundary declared in my partition function. 事实证明,在数据迁移之后,在partition_number中,有一个边界值小于我的分区函数中声明的边界。 So for example, if my minimum partition key is 5, i found values 1,2,3 and 4 in partition number 1. What i need to do is alter my partition function adding boundaries 1,2,3 and 4.How am i going to do this? 因此,例如,如果我的最小分区键是5,我在分区号1中找到值1,2,3和4.我需要做的是改变我的分区功能添加边界1,2,3和4.我是怎么回事要这样做? Does split range work in this case? 分割范围在这种情况下是否有效? How is sql server going to re arrange my data in the new partitions. sql server如何在新分区中重新排列我的数据。 Will it do the job just by altering the table? 它只是通过改变表来完成这项工作吗? Do i need to do something extra? 我需要做些额外的事情吗? Do i need to take a backup in case something goes wrong? 如果出现问题,我是否需要备份?

I guess your situation is the following: you have a right range partition with the lowest boundary value being 5, and a table that is being partitioned that way, eg: 我想你的情况如下:你有一个最低边界值为5的正确范围分区,以及一个以这种方式分区的表,例如:

create partition function pf (int) as range right for values (5)
create partition scheme ps as partition pf to ([PRIMARY], [PRIMARY])
create table T (part_key int constraint PK_T primary key)
on ps (part_key)

Now, if you enter the values 1, 2, 3, 4, and 5 into table T and check the distribution of values within each partition, you'll find 1, 2, 3 and 4 in partition 1, and 5 in partition 2: 现在,如果在表T中输入值1,2,3,4和5并检查每个分区中的值的分布,您将在分区1中找到1,2,3和4,在分区2中找到5 :

insert T values (1), (2), (3), (4), (5)
select part_key, $partition.pf(part_key) as partition from T

What you need to do to get each value in its own partition is: - for each new partition add a new destination filegroup, and - split the partition range starting at highest value 要在每个新分区中添加新目标文件组,并且 - 从最高值开始拆分分区范围,您需要做什么才能在其自己的分区中获取每个值

This could look like: 这可能看起来像:

alter partition scheme ps next used [PRIMARY]
alter partition function pf() split range (4)

alter partition scheme ps next used [PRIMARY]
alter partition function pf() split range (3)

alter partition scheme ps next used [PRIMARY]
alter partition function pf() split range (2)

Now, if you check again your value distribution, you'll see that all distinct values end up in a separate partition: 现在,如果再次检查您的值分布,您将看到所有不同的值最终都在一个单独的分区中:

select part_key, $partition.pf(part_key) as partition from T

But, be aware that this goes along with data movement, ie all rows with partition key values 1-4 need to be physically moved from original partition 2 to their new destination partition. 但是,请注意,这与数据移动一起,即具有分区键值1-4的所有行需要从原始分区2物理移动到其新的目标分区。 So, if there are millions of such rows, this'll take some time and will blow up your transaction log. 因此,如果有数百万个这样的行,这将花费一些时间并且会破坏您的事务日志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM