【发布时间】:2009-01-20 11:41:13
【问题描述】:
我对分区和策略、如何以及何时使用它有一些疑问。正如我从Partitioned Tables and Indexes in SQL Server 2005 了解到的,分区不仅用于可管理性,还用于提高超大型数据库表 (VLDB) 的性能。我们有一个包含数百万条记录的表。该表存储性能数据,例如指定项目被单击的次数等。我们需要每天在实际应用中评估当前月份的这些数据。我要防止的是将数据从一个表移动到另一个表,只是因为性能。 我的想法是:我在这个 VLDB 上按当年创建分区。然后我会在表和分区方案的日期字段上创建聚集索引。我不知道我是否理解正确,但我除了是,该索引将在每个分区单独创建。
一般来说,我的代码在开发阶段的样子。
/*
Maybe it looks like complicated, but instead of static upper bound,
I use function to determine end of the month for the current year.
So for example (executed in year 2009)
SELECT DATEADD(ms, -2, DATEADD(month,((DATEPART(YEAR, GetDate())-1901)*12)+1-1,31-1))
returns
2008-01-30 23:59:59.997
*/
CREATE PARTITION FUNCTION PartitionMonthlyCurrentYear(DATETIME) AS
RANGE LEFT FOR VALUES
(
DATEADD(ms, -2, DATEADD(month,((DATEPART(YEAR, GetDate())-1901)*12)+1-1,31-1)),
DATEADD(ms, -2, DATEADD(month,((DATEPART(YEAR, GetDate())-1900)*12)+1-1,31-1)),
DATEADD(ms, -2, DATEADD(month,((DATEPART(YEAR, GetDate())-1900)*12)+2-1,31-1)),
DATEADD(ms, -2, DATEADD(month,((DATEPART(YEAR, GetDate())-1900)*12)+3-1,31-1)),
DATEADD(ms, -2, DATEADD(month,((DATEPART(YEAR, GetDate())-1900)*12)+4-1,31-1)),
DATEADD(ms, -2, DATEADD(month,((DATEPART(YEAR, GetDate())-1900)*12)+5-1,31-1)),
DATEADD(ms, -2, DATEADD(month,((DATEPART(YEAR, GetDate())-1900)*12)+6-1,31-1)),
DATEADD(ms, -2, DATEADD(month,((DATEPART(YEAR, GetDate())-1900)*12)+7-1,31-1)),
DATEADD(ms, -2, DATEADD(month,((DATEPART(YEAR, GetDate())-1900)*12)+8-1,31-1)),
DATEADD(ms, -2, DATEADD(month,((DATEPART(YEAR, GetDate())-1900)*12)+9-1,31-1)),
DATEADD(ms, -2, DATEADD(month,((DATEPART(YEAR, GetDate())-1900)*12)+10-1,31-1)),
DATEADD(ms, -2, DATEADD(month,((DATEPART(YEAR, GetDate())-1900)*12)+11-1,31-1)),
DATEADD(ms, -2, DATEADD(month,((DATEPART(YEAR, GetDate())-1900)*12)+12-1,31-1))
);
/*
Create scheme on the primary file group. I'm aware about performance issues of this.
*/
CREATE PARTITION SCHEME SchemeMonthlyCurrentYear
AS PARTITION PartitionMonthlyCurrentYear
ALL TO ([PRIMARY]);
/*
Create clustered index on table and scheme
*/
CREATE CLUSTERED INDEX [IX_Log_Seiten_archive_Datum] ON [dbo].[Log_Seiten_archiv]
(
[Datum] DESC
)ON SchemeMonthlyCurrentYear(Datum)
GO
我的问题:
- 您如何看待这种方法?
- 如何删除表格 指定的分区方案?如果我删除索引,仍然无法删除方案和函数,因为仍然依赖于表 Log_Seiten_archiv
- 如何分配表以使用不同的分区功能?由于开发,我需要经常更改分区功能的定义方式,或创建新分区功能。我该如何为现有表执行此操作?例如,我想更改之前展示的函数的年份。
问候 安东·卡尔奇克
【问题讨论】:
标签: sql sql-server-2005 database-partitioning