# 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.
>
> Source : https://www.pachadata.com/en/docs/howtos/troubleshooting/memory-grants/
> Author : Rudi Bruchez · updated 2026-10-14
> Markdown version of the page, for tools and LLMs. The HTML page is the reference.


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.

```sql
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](https://github.com/rudi-bruchez/tsql-scripts/blob/main/extended-events/on-prem/query_memory_grants-create.sql).

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.


---

## About the author

Rudi Bruchez, independent SQL Server consultant since 2006: performance audits, tuning, migrations, high availability and training. For an audit or hands-on help on your server: https://www.pachadata.com/en/contact/ (remote audit: https://www.pachadata.com/en/services/remote-sql-server-audit/).
