Partition:Partiton Scheme是否指定Next Used?

简介:

在SQL Server中,为Partition Scheme多次指定Next Used,不会出错,最后一次指定的FileGroup是Partition Scheme的Next Used,建议,在执行Partition Split操作之前,都要为Partition Scheme指定Next Used。

但是,SQL Server是否提供metadata,查看Partiton Scheme是否指定Next Used FileGroup?答案是系统视图:sys.destination_data_spaces。如果存在FileGroup被指定为Next Used ,那么视图返回的Partition的个数会比Partition Function划分的分区数量多1个。

一,分析视图:sys.destination_data_spaces

该视图返回三列,表示Partition Scheme的每个Partition和FileGroup之间的关系:

  • partition_scheme_id :ID of the partition-scheme that is partitioning to the data space.                  
  • destination_id :ID (1-based ordinal) of the destination-mapping, unique within the partition scheme.     
  • data_space_id :ID of the data space to which data for this scheme's destination is being mapped.

从表的存储结构来分析这三列的意义:

  • partition_scheme_id 是数据表存储的空间,该空间不是具体的某个FileGroup。普通的表只有一个分区,只能存储在单个FileGroup中,但是,通过Partition Scheme,将表数据分割成多个分区,每个分区存储到指定的FileGroup中,在物理存储上,每个分区都是分开(separate)存储的。
  • destination_id:是Partition Number,每个分区的编号
  • data_space_id:是FileGroupID,分区存储的FileGroup。

二,测试用例

1,创建分区函数

-- create parition function
CREATE PARTITION FUNCTION pf_int_Left (int)
AS 
RANGE LEFT 
FOR VALUES (10,20);

2,创建分区scheme

--create partition scheme
CREATE PARTITION SCHEME PS_int_Left
AS 
PARTITION pf_int_Left
TO ([primary], [primary], [primary]);

3,在split partition之前,必须使用alter partition scheme 指定一个Next Used FileGroup。如果Partiton Scheme没有指定 next used filegroup,那么alter partition function split range command 执行失败,不改变partition scheme。

--split range and add new one boudary value
ALTER PARTITION FUNCTION pf_int_Left ()
split range (30);

Msg 7710, Level 16, State 1, Line 2
Warning: The partition scheme 'PS_int_Left' does not have any next used filegroup. Partition scheme has not been changed.

4,如果检查 Partiton Scheme是否指定Next Used FileGroup?

使用sys.destination_data_spaces视图来检查,该系统视图返回Partition 和filegroup之间的Mapping关系。如果一个FileGoup被alter partition scheme 标记为next used Filegroup,那么Partition 的个数会比多Partition function划分的分区多一个。

复制代码
select ps.name as PartitionSchemeName,
    ps.data_space_id as PartitionSchemeID,
    pf.name as PartitionFunctionName,
    ps.function_id as PartitionFunctionID,
    pf.boundary_value_on_right,
    dds.destination_id as PartitionNumber,
    dds.data_space_id as FileGroupID
from sys.partition_schemes ps
inner join sys.destination_data_spaces dds
    on ps.data_space_id=dds.partition_scheme_id
inner join sys.partition_functions pf
    on ps.function_id=pf.function_id
where ps.name='PS_int_Left'
复制代码

上述脚本返回3个partition,说明没有next used filegroup。

5,使用 alter partition scheme标记 next used filegroup

--alter partition scheme to mark next used filegroup
ALTER PARTITION SCHEME PS_int_Left 
NEXT USED [db_fg1];

查看分区个数

复制代码
select ps.name as PartitionSchemeName,
    ps.data_space_id as PartitionSchemeID,
    pf.name as PartitionFunctionName,
    ps.function_id as PartitionFunctionID,
    pf.boundary_value_on_right,
    dds.destination_id as PartitionNumber,
    dds.data_space_id as FileGroupID
from sys.partition_schemes ps
inner join sys.destination_data_spaces dds
    on ps.data_space_id=dds.partition_scheme_id
inner join sys.partition_functions pf
    on ps.function_id=pf.function_id
where ps.name='PS_int_Left'
复制代码

可以看到,多了一个partition,partition number=4,存放的FileGroupID=2。

6,将 FileGroup 取消标记为 next used filegroup

--alter partition scheme to cancel next used filegroup
ALTER PARTITION SCHEME PS_int_Left 
NEXT USED;

7,Merge Range移除FileGroup

--merge range
ALTER PARTITION FUNCTION pf_int_Left ()
merge range (20);

查看Partition Function指定的Boundary Value

复制代码
select pf.name as PartitionFunctionName,
    pf.function_id,
    pf.type,
    pf.type_desc,
    pf.boundary_value_on_right,
    pf.fanout,
    prv.boundary_id,
    prv.value
from sys.partition_functions pf
inner join sys.partition_range_values prv
    on pf.function_id=prv.function_id
where pf.name='pf_int_Left'
复制代码

绑定到Partition Scheme的Filegroup如下

复制代码
select ps.name as PartitionSchemeName,
    ps.data_space_id as PartitionSchemeID,
    pf.name as PartitionFunctionName,
    ps.function_id as PartitionFunctionID,
    pf.boundary_value_on_right,
    dds.destination_id as PartitionNumber,
    dds.data_space_id as FileGroupID
from sys.partition_schemes ps
inner join sys.destination_data_spaces dds
    on ps.data_space_id=dds.partition_scheme_id
inner join sys.partition_functions pf
    on ps.function_id=pf.function_id
where ps.name='PS_int_Left'
复制代码

参考文档:

How to Remember the Next Used Filegroup in a Partition Scheme

作者悦光阴
本文版权归作者和博客园所有,欢迎转载,但未经作者同意,必须保留此段声明,且在文章页面醒目位置显示原文连接,否则保留追究法律责任的权利。
分类: Partition
标签: Partition, Next Used




本文转自悦光阴博客园博客,原文链接:http://www.cnblogs.com/ljhdo/p/5039403.html,如需转载请自行联系原作者
目录
相关文章
|
3月前
|
算法 C++ 容器
【C++算法】is_partitioned、partition_copy和partition_point
【C++算法】is_partitioned、partition_copy和partition_point
|
5月前
|
搜索推荐 机器人 SEO
Leetcode 62. Unique Paths & 63. Unique Paths II
原谅我重新贴一遍题目描述,不是为了凑字数,而是为了让搜索引擎能索引到这篇文章,其实也是算一种简单的SEO。 简单描述下题目,有个机器人要从左上角的格子走到右下角的格子,机器人只能向下或者向右走,总共有多少种可能的路径?
22 0
|
8月前
|
前端开发 5G
Search space set group switching(一)
根据R17 38.300的描述,UE可以通过PDCCH monitoring adaptation机制实现power saving的目的,这其中就包括PDCCH monitoring skipping和search space set group (SSSG) switching两种机制。PDCCH monitoring skipping是R17才提出的机制,就是UE 可以在PDCCH skipping的时间内不监视 PDCCH的功能;search space set group (SSSG) switching R16提出,R17进行了部分增强。
|
算法
每个 Partition
每个 Partition
74 0
|
SQL 分布式计算 调度
【Spark】(七)Spark partition 理解 / coalesce 与 repartition的区别
【Spark】(七)Spark partition 理解 / coalesce 与 repartition的区别
414 0
get assigned pageset and my pages
get assigned pageset and my pages
72 0
get assigned pageset and my pages
|
JSON Cloud Native 数据建模
Parallel 解析
从 Knative Eventing 0.8 开始,支持根据不同的过滤条件对事件进行选择处理。通过 Parallel 提供了这样的能力。本文就给大家介绍一下这个特性。
1161 0
Parallel 解析
|
分布式计算 NoSQL 大数据
Apache Cassandra Composite Key\Partition key\Clustering key 介绍
在前面文章里面我们使用了下面语句创建了一张名为 iteblog_user 的表: cqlsh> use iteblog_keyspace; cqlsh:iteblog_keyspace> CREATE TABLE iteblog_user (first_name text , last_name .
2670 0
|
SQL C# Java
SQL Server ->> 时间函数: EOMONTH, DATEFROMPARTS, TIMEFROMPARTS, DATETIMEFROMPARTS, DATETIMEOFFSETFROMPARTS
原文:SQL Server ->> 时间函数: EOMONTH, DATEFROMPARTS, TIMEFROMPARTS, DATETIMEFROMPARTS, DATETIMEOFFSETFROMPARTS 上面几个函数都是SQL Server 2012新增的时间函数。
1075 0