我从未质疑以下两个脚本之间的效率差异:
DateKey 是类型INT
1.
DECLARE @StartDate INT = 20130101,
@EndDate INT = 20130201
SELECT UserAccountKey,
income_LT = SUM(ISNULL(income,0.0))
INTO #x
FROM WH.dbo.xxx x
WHERE x.DateKey > = @StartDate
AND x.DateKey < @EndDate
GROUP BY UserAccountKey
上面的执行是:
2.
SELECT UserAccountKey,
income_LT = SUM(ISNULL(income,0.0))
INTO #x
FROM WH.dbo.xxx x
WHERE x.DateKey > = 20130101
AND x.DateKey < 20130201
GROUP BY UserAccountKey
以下是 2 号的执行计划:
1.
快得多(2 秒与 80 秒相比) - 这是预期的吗?为什么?