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:Partiton Scheme是否指定Next Used?的更多相关文章
- Partition5:Partiton Scheme是否指定Next Used?
在SQL Server中,为Partition Scheme多次指定Next Used,不会出错,最后一次指定的FileGroup是Partition Scheme的Next Used,建议,在执行P ...
- 转 :Oracle分区表 (Partition Table) 的创建及管理
三.删除分区 You can drop partitions from range, list, or composite range-list partitioned tables. ALTER T ...
- Android Scheme协议与应用全解析
URL Scheme 的作用 客户端应用可以向操作系统注册一个 URL Scheme,该 Scheme 用于从浏览器或其他应用中启动本应用. 通过指定的 URL 字段,可以让应用在被调起后直接打开某些 ...
- Spark-RDD之Partition源码分析
概要 Spark RDD主要由Dependency.Partition.Partitioner组成,Partition是其中之一.一份待处理的原始数据会被按照相应的逻辑(例如jdbc和hdfs的spl ...
- oracle partition table 分区表详解
Oracle partition table 分区表详解 分区表就是通过使用分区技术,将一张大表,拆分成多个表分区(独立的segment),从而提升数据访问的性能,以及日常的可维护性.分区表中,每个分 ...
- Python partition() 方法
描述 Python partition() 方法用来根据指定的分隔符将字符串进行分割. 如果字符串包含指定的分隔符,则返回一个3元的元组,第一个为分隔符前面的子字符串,第二个为分隔符本身,第三个为分隔 ...
- python的partition() 方法
描述 partition() 方法用来根据指定的分隔符将字符串进行分割. 如果字符串包含指定的分隔符,则返回一个3元的元组,第一个为分隔符左边的子串,第二个为分隔符本身,第三个为分隔符右边的子串. p ...
- 电脑获取手机app内的scheme
做app开发,有时需要跳转打开外部的app应用,来促成引流或者分享等,这个时候就需要通过scheme跳转协议来完成. 使用scheme跳转外部app,就需要配置对应app的scheme,那这个sche ...
- Partition1:新建分区表
未分区的表,只能存储在一个FileGroup中:对Table进行分区后,每一个分区都存储在一个FileGroup,或分布式存储在不同的FileGroup中.对表进行分区的过程,是将逻辑上完整的一个表, ...
随机推荐
- HTML渲染过程详解
无意中看到寒冬关于前端的九个问题,细细想来我也只是对第一.二.九问有所了解,正好也趁着这个机会梳理一下自己的知识体系.由于本人对http协议以及dns对url的解析问题并不了解,所以这里之探讨url请 ...
- redux学习
redux学习: 1.应用只有一个store,用于保存整个应用的所有的状态数据信息,即state,一个state对应一个页面的所需信息 注意:他只负责保存state,接收action, 从store. ...
- mac下安装及配置tomcat
mac下的软件不像windows下的程序那样写注册表,对于tomcat的安装来说,在mac下是名符其实的绿色软件,具体操作如下: 1.到 apache官方主页 下载完整 tar.gz文件包.(没有专门 ...
- 【算法】(查找你附近的人) GeoHash核心原理解析及代码实现
本文地址 原文地址 分享提纲: 0. 引子 1. 感性认识GeoHash 2. GeoHash算法的步骤 3. GeoHash Base32编码长度与精度 4. GeoHash算法 5. 使用注意点( ...
- Atitit.研发团队与公司绩效管理的原理概论的attilax总结
Atitit.研发团队与公司绩效管理的原理概论的attilax总结 1. 四个理念 1 1.1. 绩效管理的三个目的.四个环节.五个关键2 1.2. 绩效目标smart2 2. 考核对象2 3. 绩效 ...
- WebAPI
WebAPI的Host OWIN IIS WebAPI 的handler和Filter有啥区别? WebAPI 常用 Filters Exception Filter Timer Filter Lo ...
- Outfit7 庆祝其开发工作大获丰收
走不寻常路之经验总结 每位合格应用开发人员都拥有相同的目标:灵机一动,构建独创性原型,克服各种困难,最终吸引投资者将其想法推向市场. 名声.财富以及构建更多应用的机会将接踵而至. 焦虑.改善和重复是开 ...
- 写个Fragment方便的抽象基类 BaseFragment
package com.zb.zhihuianyang.base; import android.app.Activity; import android.os.Bundle; import andr ...
- Firefox开发者专版浏览器,Web开发者利器.
2015的11月9日,Firefox迎来了自己的十周岁生日.在庆祝Firefox十周年之际,Mozilla发布了Firefox开发者专版,这是首款专门为开发者打造的浏览器. 浏览器中独特的暗色调设计. ...
- Xamarin.Android活动的生命周期
一.前言 用过Android手机的人一定会发现一种现象,当你把一个应用置于后台后,一段时间之后在打开就会发现应用重新打开了,但是之前的相关的数据却没有丢失.可以看出app的“生命”是掌握在系统手上的, ...