Skip to main content

What happens when a query spills to TempDB?

Expert MS SQL
Quick Answer When a sort or hash operation needs more memory than its grant, SQL Server writes intermediate data to TempDB. This turns an in-memory operation into disk I/O รขโ‚ฌโ€ often 10-100x slower. You'll see Sort Warnings or Hash Warnings in the execution plan. Fix: update statistics, or use OPTION(MIN_GRANT_PERCENT) hints.

Answer

A query spills when SQL Server lacks sufficient memory for operations like sort or hash. SQL offloads intermediate results to TempDB, causing heavy disk I/O and slow execution. Frequent spills indicate bad estimates, missing indexes, or insufficient memory. Repeated spills degrade overall SQL Server performance.

S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice