SQL Server Interview Question #209

What is a memory grant in SQL Server?

Advanced Query Optimization Senior Advanced

Detailed Explanation

A memory grant is workspace memory reserved for an executing query, primarily for operators such as Sort and Hash Match.

If the grant is too small, an operator may spill to tempdb. If it is excessively large, the query can reserve memory it does not need and reduce concurrency by making other queries wait for workspace memory.

Memory grant quality depends heavily on cardinality estimates. Modern SQL Server versions include memory grant feedback features for eligible workloads that can adjust future grants based on previous executions.