Microsoft Certified IT Professional Rudi Bruchez EI Microsoft Certified IT Professional

Rudi Bruchez EI · www.pachadata.com · rudi@pachadata.com · +33 6 22 48 76 99
Consulting, audit, performance tuning, solutions, training
SQL Server OLTP and BI / NoSQL

Version of October 14, 2026 (4308dcaa) · https://www.pachadata.com/en/docs/howtos/troubleshooting/memory-grants/

Identify excessive memory grants

Diagnose memory grants that are too large or too small in SQL Server: varchar(max) sizing, actual plans, the query_memory_grant_usage event, tempdb spills.

When an execution plan has to sort, or to build a hash table in memory, the query optimizer has to work out how much memory to reserve for those operations.

Take this query as an example.

SELECT *
FROM Contact.Contact c
ORDER BY c.LastName, c.FirstName;

SQL Server has to reserve enough memory to hold the whole table — SELECT * asks for everything — and perform the sort.

The estimate of how much memory to reserve depends on the cardinality estimate and on the size of the data. A bad estimate therefore has two possible causes:

  • a bad cardinality estimate;
  • badly sized variable-length types.

Excessive grants

If you systematically declare your varchar columns with a maximum length that is far too large, varchar(max) being the extreme case, you force the optimizer to ask for too much memory.

The memory that was reserved, and the memory actually used, both appear in the actual execution plan.

You can trace how that memory is used with the sqlserver.query_memory_grant_usage event, using the script on my GitHub.

Pay particular attention to the usage_percent event field.

Spills to tempdb

An under-sized grant causes sorts or hashes to spill to disk, in tempdb.

Contact

I have been an independent SQL Server consultant since 2006. I help when an application slows down, when a server costs too much in storage or licenses, or when a migration must not stop production: audit and diagnosis, query and index tuning, migrations, high availability, training. On site, or as a remote audit delivered in five working days.

rudi@pachadata.com · +33 6 22 48 76 99 · www.pachadata.com/en/contact/