在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

Partition5:Partiton Scheme是否指定Next Used?的更多相关文章

  1. Partition:Partiton Scheme是否指定Next Used?

    在SQL Server中,为Partition Scheme多次指定Next Used,不会出错,最后一次指定的FileGroup是Partition Scheme的Next Used,建议,在执行P ...

  2. Android Scheme协议与应用全解析

    URL Scheme 的作用 客户端应用可以向操作系统注册一个 URL Scheme,该 Scheme 用于从浏览器或其他应用中启动本应用. 通过指定的 URL 字段,可以让应用在被调起后直接打开某些 ...

  3. 电脑获取手机app内的scheme

    做app开发,有时需要跳转打开外部的app应用,来促成引流或者分享等,这个时候就需要通过scheme跳转协议来完成. 使用scheme跳转外部app,就需要配置对应app的scheme,那这个sche ...

  4. Sql Server 分区之后增加新的分区

    随着时间的推移,你可能会希望为已分区的表添加额外的分区(例如,可以为每一个新年创建一个新的分区).要增加一个新的分区,可以使用ALTER PARTITION SCHEME和ALTER PARTITIO ...

  5. android deep link(深度链接)与自定义协议!

    此自定义仅供参考! 首先打开androidManifest.xml 在MainActivity中添加如下内容: <activity android:name=".MainActivit ...

  6. PhpSms 稳定可靠的php短信发送库

    可能是目前最聪明.优雅的PHP短信发送库了.从此不再为各种原因造成的个别短信发送失败而烦忧! phpsms的任务均衡调度功能由toplan/task-balancer提供. GitHub地址:http ...

  7. SqlServer分区表概述(转载)

    什么是分区表 一般情况下,我们建立数据库表时,表数据都存放在一个文件里. 但是如果是分区表的话,表数据就会按照你指定的规则分放到不同的文件里,把一个大的数据文件拆分为多个小文件,还可以把这些小文件放在 ...

  8. Android学习笔记(四)

    一个应用程序是有很多活动构成的,使用Intent在活动间移动. Intent分为显式和隐式两种: 1.显示Intent: 新建一个布局文件,命名为second_layout.xml,代码如下 < ...

  9. 活动组件(三):Intent

    大多数的安卓应用都不止一个Activity,而是有多个Activity.但是点击应用图标的时候,只会进入应用的主活动. 因此,前面我已经建立了一个主活动了,名字是myActivity,现在我再建立一个 ...

随机推荐

  1. javaScript 迭代器

    for ...of 语句 "use strict"; var name = ['a','b','c']; var mark = [1, 2, 3]; for(var i of na ...

  2. shell 文件比较符

    文件夹不存在创建 if [ ! -d "/data/" ];then mkdir /data else echo "文件夹已经存在" fi 文件存在则删除 if ...

  3. js之切换全屏和退出全屏实现

    应用场景:比如很多网页游戏全屏之类的,或者是网上看小说等. 核心代码: //控制全屏 function enterfullscreen() { //进入全屏 $("#fullscreen&q ...

  4. Oracle 导出表结构

    Oracle导出表结构 select A.Table_Name 表名 , -- A.column_name 字段名 A.column_name 字段名, A.data_type 数据类型, A.dat ...

  5. Refused to execute script from '...' because its MIME type ('') is not executable, and strict MIME type checking is enabled.

    写在前面 部署项目到weblogic上启动首页访问空白, 浏览器控制台报如题错误. web.xml中把响应头添加防止攻击的报文过滤器禁用就行了(仅仅是为了启动), 以下为转载内容, 可以根据需要自行测 ...

  6. 【Python】解析Python中的线程与进程

    基础知识 线程 进程 两者的区别 线程的类型 Python 多线程 GIL 创建多线程 线程合并 线程同步与互斥锁 可重入锁(递归锁) 守护线程 定时器 Python 多进程 创建多进程 多进程通信 ...

  7. 从ASP.NET到ASP.NET Core差异变化

    MSDN原文:链接 ASP.NET Core项目为开发人员提供了针对.NET Core,.NET Framework2种实现方式,根据官网通告NETCORE3.0后将取消对.NET Framework ...

  8. openvswitch2.11.0修改源码后重新编译

    一:推文 https://www.jianshu.com/p/923f49c290f5(可以删除运行当中的DataPath内核) https://github.com/ebiken/doc-netwo ...

  9. “无法启动IIS Express Web服务器”的解决办法

    “无法启动IIS Express Web服务器”的解决办法 听语音 原创 | 浏览:259 | 更新:2019-07-15 13:02 1 2 3 4 5 6 7 分步阅读 在使用visual stu ...

  10. pipeline配置sonar和自动化

    1.sonar配置webhooks, 2.url填写jenkins的地址:http://jenkinsurl/sonarqube-webhook/ 3.前提:jenkins配置好sonar的scann ...