When a client calls me because their SQL Server is slow, the first thing they usually say is "we have a bad query." And sometimes they're right. But more often than not, the query is a symptom, not the cause.

After 12+ years of troubleshooting performance issues across hundreds of environments, I've learned to check the infrastructure first and the queries second. Here's why.

The usual suspects

Before you open Query Store or fire up an execution plan, check these three things:

1. TempDB contention

TempDB is SQL Server's shared scratch pad. Every sort, hash join, table variable, and version store operation uses it. When multiple sessions compete for the same allocation pages, you get latch waits — and everything grinds to a halt.

I once cut a client's average query time by 40% just by adding more TempDB data files and enabling trace flag 1118. Zero query changes.

Quick check: Look for PAGELATCH_UP and PAGELATCH_EX waits on pages in database ID 2. If you see them, TempDB configuration is your first fix.

2. Memory pressure

SQL Server loves RAM. It caches data pages in the buffer pool so it doesn't have to read from disk. When there isn't enough memory, it constantly swaps pages in and out — a phenomenon called "page life expectancy" dropping.

3. Outdated statistics

The query optimizer builds execution plans based on statistics — estimates of data distribution. When statistics are stale, the optimizer makes bad choices: nested loops where it should hash join, seeks where it should scan.

-- Check when statistics were last updated
SELECT
    t.name AS TableName,
    s.name AS StatName,
    STATS_DATE(s.object_id, s.stats_id) AS LastUpdated
FROM sys.stats s
JOIN sys.tables t ON s.object_id = t.object_id
ORDER BY STATS_DATE(s.object_id, s.stats_id) ASC;

If you see statistics that haven't been updated in weeks on active tables, that's likely contributing to your performance problems.

The real debugging workflow

Here's the process I follow for every performance engagement:

  1. Check wait stats — they tell you what SQL Server is waiting on. This is your starting point, always.
  2. Review system configuration — max memory, MAXDOP, cost threshold for parallelism, TempDB files.
  3. Examine storage latencysys.dm_io_virtual_file_stats will show you if disk I/O is the bottleneck.
  4. Then look at queries — now you have context for why specific queries are slow.

The takeaway

Query tuning is important — but it's step four, not step one. If your SQL Server is slow, start with the environment. You might save yourself hours of execution plan analysis and find a fix that helps every query, not just one.


Need help diagnosing a slow SQL Server? Book a free 30-minute consultation and I'll point you in the right direction.