很多公司流行使用資料倉儲進行資料分析,一般從線上資料來源備庫(mirror,logshipping,slave等)抽取到ods 層
在從ods層到dw再到dm.特別在ods層到dw時,資料的清洗裝載需要一定的時間和硬體資源.
但是當硬體成為瓶頸時,怎麼能快速完成清洗轉載,及時的提供資料分析?
下面提供一種方法使用Ssis 載入到 ods層後,直接通過分區表把資料載入到 dw
1 準備
- /*create filegroup*/
- ALTER DATABASE [testxwj] ADD FILEGROUP [account_1]
- go
- ALTER DATABASE [testxwj] ADD FILEGROUP [account_2]
- go
- ALTER DATABASE [testxwj] ADD FILEGROUP [account_3]
-
- /*create file to filegroup*/
-
- ALTER DATABASE [testxwj] ADD FILE ( NAME = N'account_1', FILENAME = N'E:\account_1.ndf' , SIZE = 409600KB , FILEGROWTH = 20480KB ) TO FILEGROUP [account_1]
- GO
- ALTER DATABASE [testxwj] ADD FILE ( NAME = N'account_2', FILENAME = N'E:\account_2.ndf' , SIZE = 409600KB , FILEGROWTH = 20480KB ) TO FILEGROUP [account_2]
- GO
- ALTER DATABASE [testxwj] ADD FILE ( NAME = N'account_3', FILENAME = N'E:\account_3.ndf' , SIZE = 409600KB , FILEGROWTH = 20480KB ) TO FILEGROUP [account_3]
- GO16
2 使用ssis copy table
- sp_spaceused accountdetail;
- /* delete EarnTime is not null*/
-
- /*23 sec*/
- delete from accountdetail where EarnTime is null
- /*26 sec*/
- delete from accountdetail where isnull(CommitStatus,0)<1
- /*12 sec*/
- delete from accountdetail where isnull(EarnStatus,0) =0
對傳輸過來的表進行分區
- /*create partition function*/
- declare @bdate char(8),@edate varchar(8),@sql varchar(500)
- select
- @bdate=convert(char(8),GETDATE()-1 ,112)
- ,@edate=convert(char(8),GETDATE() ,112)
- select @bdate,@edate;
- set @sql='
- CREATE PARTITION FUNCTION ac_EarnTime (datetime)
- AS11 RANGE RIGHT FOR VALUES ( '''+@bdate+''' ,'''+@edate+''')'
- execute(@sql)
- /*create partition schema*/
- CREATE PARTITION SCHEME ac_schema_ac_EarnTime
- AS PARTITION ac_EarnTime TO (account_1,account_2,account_3);
- /*create partition table */
- alter table accountdetail
- alter column EarnTime datetime not null;
- alter TABLE accountdetail
- add CONSTRAINT [PK_PARTITIONmis] PRIMARY KEY
- ( id,EarnTime
- )ON ac_schema_ac_EarnTime(EarnTime)
把分區partition 2指向給 dw 值得注意的是 accountdetail_dw 必須跟partition 2 分區所在同一個檔案組
- /*switch accountdetail to accountdetail_dwl*/
- ALTER TABLE accountdetail SWITCH PARTITION 2 TO accountdetail_dw ;
- /**/
整個過程在 5分鐘內.資料倉儲最重要的還在當初的設計和選型.
原文標題:當硬體成為瓶頸時怎麼提高資料倉儲的載入?
連結:http://www.cnblogs.com/xwj1985/archive/2010/08/19/1803272.html