LATCH_EX Wait Type in SQL Server

Part of the SQL Server Wait Types Library, every wait type explained.Related deep dive: PAGELATCH_EX, TempDB Allocation ContentionRelated pillar: Performance & Troubleshooting

LATCH_EX is a wait for an exclusive latch on an internal SQL Server structure that is not a data or index page. SQL Server uses latches to protect all kinds of in-memory structures. Everything that is not a buffer page shows up here under LATCH_* rather than PAGELATCH_* or PAGEIOLATCH_*.

On its own the name tells you very little. The useful detail is the latch class, which names the subsystem under contention.

Is It a Problem?

A small amount is normal. It is worth investigating when LATCH_EX climbs into the top of your wait profile, because that means one specific internal structure is a serialisation point for your workload.

Common Causes

  • ACCESS_METHODS_DATASET_PARENT: large parallel scans, a very common cause on reporting workloads.
  • LOG_MANAGER or related classes: heavy transaction log activity.
  • Allocation and metadata latches under heavy DDL or temp object churn.

What To Do

  1. Look at sys.dm_os_latch_stats and find the latch class with the most wait time. The DMV groups all latch modes together per class, which is the right altitude for analysis anyway.
  2. Target that subsystem. For ACCESS_METHODS_DATASET_PARENT, review parallelism (MAXDOP, cost threshold) and index the large scans driving it.
  3. Treat the latch class as the real signal, not the generic LATCH_EX name.
  4. For before/after comparisons, latch stats can be reset with DBCC SQLPERF ('sys.dm_os_latch_stats', CLEAR); so you measure just your test window.

How To See It

Rank it against everything else with Get-WaitStatistics, then break it down by class in sys.dm_os_latch_stats.


Where To Go Next

If LATCH_EX is sitting near the top of your wait stats, these are the next places to look.

Related waits: LATCH_DT · LATCH_KP · LATCH_NL

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *