I have a
T-SQL query with four inner joins, I executed the query in
Actual Execution Plan selected. When I review the generated plan I saw the warning icon on
What is the reason for this warning in
The Query Plan URL: https://www.brentozar.com/pastetheplan/?id=HJULL9H4N
What is the reason for this warning in Sort operator?
You can see the warning description in properties of the element. I’m sure you will see information like below:
Operator used tempdb to spill data during execution…..
It means that memory which was granted for the query turned out to be less than it needed. Two possible reasons for that:
- Wrong cardinality estimation so the query asked for the less memory grant than it really needed
- Lack of memory so the query asked enough memory but got less
Detailed information about memory grant can be found in the properties window of
SELECToperation from your query plan.
I am not writing a complete new answer. Most of it is covered between the comments and answer by Denis.
Two possible reason mentioned.
Wrong cardinality estimation and
Lack of memory. I will explain how you can rule out
Lack of Memory.
MaxQueryMemory under MemoryGrantInfo (once you right click the leftmost select node): Maximum amount of memory available for individual query grant in KB, if the query requires memory to run.
So if the MaxQueryMemory is larger than requested memory it is a good indication that sort warning is NOT due lack memory, it is rather due bad cardinality estimation.
A worth reading about Understanding SQL server memory grant