我有一個5年的數據集分爲季度表。我也有一個主視圖,將它們連接在一起。當用戶需要超過四分之一的數據時,他們經常使用主視圖,而不是將多個小區連接在一起。SQL Server表值功能性能
我的問題是,一個表值函數接受日期範圍,並只返回來自必要分區的記錄比查詢整個主視圖更快?
這是我當前視圖定義:
ALTER VIEW [dbo].[loandetails_test]
AS
SELECT *
FROM loandetails05
where year(date) = 2005
UNION
SELECT *
FROM loandetails06
where year(date) = 2006
UNION
SELECT *
FROM loandetails07
where year(date) = 2007
UNION
SELECT *
FROM loandetails08
where year(date) = 2008
UNION
SELECT *
FROM loandetails1q09
where date >= '1/1/2009' and date < '4/1/2009'
UNION
SELECT *
FROM loandetails2q09
where date >= '4/1/2009' and date < '7/1/2009'
UNION
SELECT *
FROM loandetails3q09
where date >= '7/1/2009' and date < '10/1/2009'
UNION
SELECT *
FROM loandetails4q09
where date >= '10/1/2009' and date < '1/1/2010'
UNION
SELECT *
FROM loandetails1q10
where date >= '1/1/2010' and date < '4/1/2010'
UNION
SELECT *
FROM loandetails2q10
where date >= '4/1/2010' and date < '7/1/2010'
UNION
SELECT *
FROM loandetails3q10
where date >= '7/1/2010' and date < '10/1/2010'
UNION
SELECT *
FROM loandetails4q10
where date >= '10/1/2010' and date < '1/1/2011'
union
SELECT *
FROM loandetails_CURRENT
where date >= '1/1/2011' and date < '4/1/2011'
GO
可能。這當然很大程度上取決於如何編寫表值函數。但唯一的方法是使用主視圖和使用表值函數來衡量性能。 – HLGEM 2011-02-10 18:47:40