Data Monitoring / SQL Server Query Performance
SQL Server: Sort and hash spills
A query unexpectedly writes large temporary work to disk. Inspect execution evidence for spills alongside row estimates and granted memory.
Environment and inputs: SQL Server 2019–2025 where the referenced feature is supported; Query Store and diagnostic collection require appropriate configuration and permissions. Azure SQL behavior can differ.
Failure scenario
A query unexpectedly writes large temporary work to disk. Confirm the cause before choosing a fix.
What to check first
Inspect execution evidence for spills alongside row estimates and granted memory. Record the time, affected scope and a time period when the system was working normally.
Fix the confirmed cause
Correct estimation or query shape where justified and compare tempdb work under representative parameters. Write the expected result first. Change one relevant setting at a time.
Check the result and share your findings
Repeat the check for sort and hash spills using the same scope and a typical operating period. Check that the original problem is resolved, the expected records are present, and systems that use the result still receive correct data.
If the change loses needed data, produces wrong results or increases delay, restore the saved settings through the agreed recovery process.
Limits and precautions
Use read-only access where possible. Limit queries to the time period or data you need. Test changes in an approved environment; this example has not been tested on your systems. Do not include passwords, access tokens or sensitive records in shared results.