我是这方面的初学者,所以希望你能提供帮助。我在 SQL Server 2008R2 中工作,并且有一个由四个表组成的视图,这些表全部连接在一起:
SELECT DISTINCT ad.award_id,
bl.funding_id,
bl.budget_line,
dd4.monthnumberofyear AS month,
dd4.yearcalendar AS year,
CASE
WHEN frb.full_value IS NULL THEN '0'
ELSE frb.full_value
END AS Expenditure_value,
bl.budget_id,
frb.accode,
'Actual' AS Type
FROM dw.dbo.dimdate5 AS dd4
LEFT OUTER JOIN dbo.award_data AS ad
ON dd4.fulldate BETWEEN ad.usethisstartdate AND
ad.usethisenddate
LEFT OUTER JOIN dbo.budget_line AS bl
ON bl.award_id = ad.award_id
LEFT OUTER JOIN dw.dbo.fctresearchbalances AS frb
ON frb.el3 = bl.award_id
AND frb.element4groupidnew = bl.budget_line
AND dd4.yearfiscal = frb.yr
AND dd4.monthnumberfiscal = frb.period
该视图有 9 列和 150 万行,并且还在不断增长。从此视图中选择 * 对所有行都需要 20 分钟。我在加入的表中的字段上添加了索引,并将其改进为 10 分钟。我的问题是我还能做些什么来让选择运行得更快?
非常感谢,紫罗兰。