http://www.databasejournal.com/features/mssql/article.php/3640891
1,创建分区
创建分区
2,创建分区函数
分区函数
3,创建分区架构
创建分区架构
4,创建表
创建表
5,创建聚合索引
创建聚合索引
分区函数共有三个分临界值:100,200,300,有四个文件组[Data Partition DB FG1]到[... FG4],存储规则如下:
分区号 | 范围 | 文件组名 |
1 | x<=100 | [Data Partition DB FG1] |
2 | 100<x<=200 | [Data Partition DB FG2] |
3 | 200<x<=300 | [Data Partition DB FG3] |
4 | 300<x | [Data Partition DB FG4] |
现在要求加入500这个临界值,并加入文件组[Data Partition DB FG5],如下操作:
1,建立文件组:
ALTER DATABASE [Data Partition DB2]ADD FILEGROUP [Data Partition DB FG5]
ALTER DATABASE [Data Partition DB2]ADD FILE(NAME='Data Partition DB FG5',
FILENAME='D:\Database\Data Partition DB FG5.ndf') TO FILEGROUP [Data Partition DB FG5];
2,更改分区架构
ALTER DATABASE [Data Partition DB2]ADD FILE(NAME='Data Partition DB FG5',
FILENAME='D:\Database\Data Partition DB FG5.ndf') TO FILEGROUP [Data Partition DB FG5];
ALTER PARTITION SCHEME [Data Partition Scheme]
NEXT USED [Data Partition DB FG5];
3,更改分区函数NEXT USED [Data Partition DB FG5];
ALTER PARTITION FUNCTION [Data Partition Range](int)
SPLIT RANGE (500)
SPLIT RANGE (500)
然后我们来看有什么变化:
分区架构:
USE [Data Partition DB2]
GO
CREATE PARTITION SCHEME [Data Partition Scheme] AS PARTITION [Data Partition Range]
TO ([Data Partition DB FG1],
[Data Partition DB FG2],
[Data Partition DB FG3],
[Data Partition DB FG5],
[Data Partition DB FG4])
GO
CREATE PARTITION SCHEME [Data Partition Scheme] AS PARTITION [Data Partition Range]
TO ([Data Partition DB FG1],
[Data Partition DB FG2],
[Data Partition DB FG3],
[Data Partition DB FG5],
[Data Partition DB FG4])
分区函数:
USE [Data Partition DB2]
GO
CREATE PARTITION FUNCTION [Data Partition Range](int) AS RANGE LEFT FOR VALUES (100, 200, 300, 500)
GO
CREATE PARTITION FUNCTION [Data Partition Range](int) AS RANGE LEFT FOR VALUES (100, 200, 300, 500)
这时的存储规则:
分区号 | 范围 | 文件组名 |
1 | x<=100 | [Data Partition DB FG1] |
2 | 100<x<=200 | [Data Partition DB FG2] |
3 | 200<x<=300 | [Data Partition DB FG3] |
4 | 300<x<=500 | [Data Partition DB FG5] |
5 | 500<x | [Data Partition DB FG4] |
可以看到新加的文件组并没有排到最后一们,而FG4成为新的临界点。那我们加入新的临界点400呢,
变化如下
分区架构:
USE [Data Partition DB2]
GO
CREATE PARTITION SCHEME [Data Partition Scheme] AS PARTITION [Data Partition Range]
TO ([Data Partition DB FG1],
[Data Partition DB FG2],
[Data Partition DB FG3],
[Data Partition DB FG5],
[Data Partition DB FG6],
[Data Partition DB FG4])
GO
CREATE PARTITION SCHEME [Data Partition Scheme] AS PARTITION [Data Partition Range]
TO ([Data Partition DB FG1],
[Data Partition DB FG2],
[Data Partition DB FG3],
[Data Partition DB FG5],
[Data Partition DB FG6],
[Data Partition DB FG4])
分区函数:
USE [Data Partition DB2]
GO
CREATE PARTITION FUNCTION [Data Partition Range](int) AS RANGE LEFT FOR VALUES (100, 200, 300,400, 500)
GO
CREATE PARTITION FUNCTION [Data Partition Range](int) AS RANGE LEFT FOR VALUES (100, 200, 300,400, 500)
存储规则将变为
分区号 | 范围 | 文件组名 |
1 | x<=100 | [Data Partition DB FG1] |
2 | 100<x<=200 | [Data Partition DB FG2] |
3 | 200<x<=300 | [Data Partition DB FG3] |
4 | 300<x<=400 | [Data Partition DB FG5] |
5 | 400<x<=500 | [Data Partition DB FG6] |
6 | 500<x | [Data Partition DB FG4] |
所以对于具体时间维的数据仓库来说,时间做为临界点,是不断增加的,我们一开始创建事实表分区时,最后一个分区应该叫做类似[Data Partiotion DB FG LAST]的名称,
最后,有一个问题还没有实践,对于一个有1000w条记录的文件组,用一个文件保存和用十个文件保存,查询效率会有什么样的不同呢?