Partition Range 的 Split 和 Merge 操作
2015-12-13 21:21
351 查看
对于分区表,在 empty partition 上进行 Partition Range 的 Split 和 Merge 操作,实际上是metadata-only change,Data 并不会移动。如果在 non-empty 的partition上进行split和merge,是十分耗时的。
Best Practice: Maintain an empty partition on both ends of the partitioned table and ensure that only empty partitions are split and merged in a sliding window scenario.
一,Split
拆分 Partition Range,增加一个Boundary value,将一个 partition 一分为二,增加分区。在拆分Partition时,首先在Partition Scheme上指定新分区用以存储数据的文件组,其次在Partition Function上指定新的Boundary value。
1,Mark Next Used FileGroup
2,Split Range
将Primary FileGroup 标记为next Used state,新增的partition就会使用标记为next Used state的FileGroup来存储数据。
二,Merge
删除分区,通过将两个“相邻”的分区合并在一起来实现,相邻是指partition column值在逻辑上相邻,由于不需要额外的FileGroup来存储数据,所以不需要显式改变Partition Scheme。在merge range之后,partition Scheme会自动将被删除partition的FileGroup 从FileGroup List中remove。
三,分区操作的最佳实践
1,当需要删除整个分区时,可以使用以下方法:先将partition的data switch out 到一个新的 staging table,然后合并分区,drop staging table。
Use SWITCH with MERGE to drop partition data: Switch out the partition and remove the partition's boundary value using MERGE.Use Drop TABLE to delete partition data by switching a partition out to a staging table and truncating the staging table.
Best Practice: Maintain an empty partition on both ends of the partitioned table and ensure that only empty partitions are split and merged in a sliding window scenario.
-- create parition function CREATE PARTITION FUNCTION pf_int_Left (int) AS RANGE LEFT FOR VALUES (10,20); --create partition scheme CREATE PARTITION SCHEME PS_int_Left AS PARTITION pf_int_Left TO ([primary], [primary], [primary]);
一,Split
拆分 Partition Range,增加一个Boundary value,将一个 partition 一分为二,增加分区。在拆分Partition时,首先在Partition Scheme上指定新分区用以存储数据的文件组,其次在Partition Function上指定新的Boundary value。
1,Mark Next Used FileGroup
--Mark Next Used FileGroup alter partition scheme PS_int_Left Next Used [primary]
2,Split Range
--Split Range using distinct boudary value alter partition function pf_int_Left() split range(30)
将Primary FileGroup 标记为next Used state,新增的partition就会使用标记为next Used state的FileGroup来存储数据。
二,Merge
删除分区,通过将两个“相邻”的分区合并在一起来实现,相邻是指partition column值在逻辑上相邻,由于不需要额外的FileGroup来存储数据,所以不需要显式改变Partition Scheme。在merge range之后,partition Scheme会自动将被删除partition的FileGroup 从FileGroup List中remove。
--Merge Range using existing boundary value alter partition function pf_int_Left() merge range(20)
三,分区操作的最佳实践
1,当需要删除整个分区时,可以使用以下方法:先将partition的data switch out 到一个新的 staging table,然后合并分区,drop staging table。
Use SWITCH with MERGE to drop partition data: Switch out the partition and remove the partition's boundary value using MERGE.Use Drop TABLE to delete partition data by switching a partition out to a staging table and truncating the staging table.
相关文章推荐
- 通讯(transport)
- 解题报告
- Centos7 readme
- 关于c++提取符号“>>”的重载问题
- C语言知识总结
- leetcode -- Combination -- 重点,求可能的0,1全排列
- [CV] bundler安装
- XSS quiz 6~10解题方案
- Ubuntu下安装matlab应用程序图文教程(详细 全面)
- C#——类和继承
- 杭电Red and Black。。。。水题
- vmware中的3种网络模式:桥接、NAT(地址转换)、host-only
- 二叉排序树
- 创建SSH Key连接github或gitlab
- android:gravity 和 android:layout_gravity 区别
- 创建SSH Key连接github或gitlab
- c语言总结
- 文字检测
- nova http 409 虚拟机状态重置
- [javase学习笔记]-4.4 函数的重载