Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Performance of GROUP BY vs. PARTITION BY

$
0
0

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. 


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>