Hi all,
Apologies if this has already been addressed but I couldn't find anything useful.
My problem is this:
SELECT Identifier, SUM(Value)
FROM dbo.Table (NOLOCK)
GROUP BY Identifier
vs.
SELECT Identifier, SUM(Value) OVER (PARTITION BY Identifier)
FROM dbo.Table (NOLOCK)
They both give me the same results but have wildly different execution plans (as you would expect). The latter seems to take most of its time in sorting the rows, the former in Hash matching.
At present, the GROUP BY seems to be slightly better performance wise, but I was wondering if anyone has an opinion on which to use. Is there any obvious way of tweaking the PARTITION BY to reduce the amount of time it spends sorting?
Cheers.