I have the following query in the StackOverflow2010 database:
SELECT Id,
OwnerUserId,
CreationDate,
Body
FROM Posts
ORDER BY LastEditorDisplayName
The execution plan shows me the desired memory
Erik Darling states that Operators that will use memory grants are
The most common reasons for memory grants are Sorts and Hashes. You may also see them for an Optimized Nested Loops Join, but whatever.
so for my execution plan, it looks like the sort operator is the only one which requires memory.
The sort operator shows that it expects to sort 3,729,200 row of 4093B
3,729,200 * 4093B = 15,263,615,600B
15,263,615,600 / 1024 = 14,905,875KB
so the sum of the memory required for the sort appears to be 14,905,875, yet the desired memory grant for the query is 18,817,952, why is there a discrepancy?