EN
Free assessment

Blog · SQL Server

SQL Server Performance Tuning: 10 Common Causes of Slowness and How to Diagnose Each

A slow SQL Server almost always traces back to a few causes: missing or poorly designed indexes, bad plans from parameter sniffing, stale statistics, blocking, tempdb pressure, insufficient I/O and memory, non-sargable queries and configuration. Start with Query Store and the wait-stats DMVs to find the cause before changing anything.

A slow SQL Server usually arrives as the complaint “the database froze”, and the first question is “slow where?”. One screen, a nightly report, the whole server on Monday mornings? Each answer points to a different cause. In this article we list the 10 causes we see most in consulting and in the systems we maintain, and how to identify each one with tools that ship in the product: Query Store, DMVs and execution plans. We have worked with SQL Server in custom systems since 2008, including databases with SSDT and versioned migrations that have supported WebVendas since 2018.

Before changing anything: measure

Three short steps avoid weeks of trial and error.

  1. Define the symptom: which query, what time, how long before and after.
  2. Look at waits. The sys.dm_os_wait_stats DMV shows where the server spends its time: CPU, I/O, locking, memory, network.
  3. Find the expensive queries in Query Store (or in sys.dm_exec_query_stats, if it is off), sorted by total duration, CPU and logical reads.
SELECT TOP 10 wait_type, wait_time_ms, waiting_tasks_count
FROM sys.dm_os_wait_stats
WHERE wait_type NOT IN ('SLEEP_TASK','LAZYWRITER_SLEEP','XE_TIMER_EVENT',
                        'BROKER_TASK_STOP','CHECKPOINT_QUEUE','SQLTRACE_BUFFER_FLUSH')
ORDER BY wait_time_ms DESC;

With that in hand, work through the list.

1. Missing or poorly designed indexes

This is the most frequent cause we find. Without a suitable index, SQL Server reads the whole table (a scan) to find a few rows.

How to diagnose: in the execution plan, look for Table Scan or Clustered Index Scan on large tables with a selective filter, and for the missing-index hint in the plan. The sys.dm_db_missing_index_details DMV lists candidates.

What to do: create indexes with the filter and join columns in order of selectivity and use INCLUDE for columns that are only read. Do not accept every suggestion: consolidate the overlapping ones. Remember that each index costs writes and space.

2. Too many, duplicate or fragmented indexes

The opposite extreme hurts too. Tables with many indexes make INSERT, UPDATE and DELETE slow.

How to diagnose: sys.dm_db_index_usage_stats shows indexes with many writes and no reads. Compare definitions to find duplicates. For fragmentation, use sys.dm_db_index_physical_stats.

What to do: drop or consolidate the unused ones (after watching a full business cycle, including month-end close). Reorganize or rebuild only indexes that are truly fragmented and large. On modern disks, fragmentation matters less than it used to, and updating statistics usually pays off more.

3. Stale statistics

The optimizer picks a plan from its row estimates. Old statistics produce wrong estimates and bad plans, such as nested loops over millions of rows.

How to diagnose: in the actual plan, compare “estimated rows” with “actual rows”. A large gap is the signal. Use sys.dm_db_stats_properties to see the date and the modifications since the last update.

What to do: run UPDATE STATISTICS on large, heavily loaded tables, schedule the maintenance and keep AUTO_UPDATE_STATISTICS on. In recent versions, the compatibility level also changes the cardinality estimator, so test it.

4. Parameter sniffing

A stored procedure runs in milliseconds for customer A and in minutes for customer B. The plan was compiled with the first execution’s parameters and reused.

How to diagnose: Query Store shows the same query with more than one plan and a wide duration spread. In the plan, compare the compile-time parameter with the runtime one.

What to do: in increasing order of intrusion: rewrite the query, OPTION (RECOMPILE) when compile cost is worth it, OPTIMIZE FOR with a representative value, split the logic into procedures for distinct cases, or force the stable plan through Query Store. In recent versions, parameter sensitive plan optimization helps in part of the cases.

5. Non-sargable queries

“Sargable” means the filter can use an index. Functions on the column prevent that.

-- Slow: the function on the column forces a scan
WHERE YEAR(OrderDate) = 2026

-- Fast: an open range uses the index
WHERE OrderDate >= '2026-01-01' AND OrderDate < '2027-01-01'

How to diagnose: a scan on an indexed column, with CONVERT, ISNULL, LIKE '%text' or an implicit type conversion in the predicate. Implicit-conversion warnings show up in the plan.

What to do: rewrite the predicate, align data types (for example varchar against nvarchar, common in ORMs) or create an indexed computed column.

6. Blocking and deadlocks

The query is fast but it waits. A long transaction holds locks and the others queue up.

How to diagnose: sys.dm_exec_requests with blocking_session_id filled in, and sys.dm_tran_locks. Deadlock events sit in the system_health Extended Events session. LCK_M_* waits at the top of the wait stats confirm it.

What to do: shorten transactions, access tables in the same order, avoid user interaction inside a transaction and create indexes that narrow lock scope. Consider READ_COMMITTED_SNAPSHOT, which keeps readers from blocking writers, after measuring tempdb usage.

7. tempdb pressure

tempdb holds temp tables, table variables, sort spills and row versions. Contention there affects the whole server.

How to diagnose: PAGELATCH_* waits on allocation pages, frequent file growth and sys.dm_db_task_space_usage per session. Spills appear in the plan as sort or hash warnings in tempdb.

What to do: use several data files of equal size (the modern installer already suggests this), size tempdb so it does not grow at peak hours, put it on fast disk and fix the queries that spill because of low memory or a wrong estimate.

8. Insufficient I/O and memory

If the dominant waits are PAGEIOLATCH_*, the server is waiting on disk. If memory is small for the working set, pages leave the cache constantly.

How to diagnose: per-file latency in sys.dm_io_virtual_file_stats, the Page Life Expectancy counter and the max server memory setting. High read and write latency points to storage.

What to do: first cut unnecessary reads with correct indexes and queries. Then adjust max server memory (leave room for the operating system), separate log, data and tempdb, and review storage. Hardware comes last.

9. Plan and code: cursors, loops and too many queries

Code that processes row by row (cursors, WHILE loops, scalar functions called per row) scales poorly. The same goes for an application that fires thousands of small queries instead of one (the ORM N+1 problem).

How to diagnose: in Query Store, queries with thousands of executions and a low individual cost that add up to the most time. In the plan, user-defined scalar functions hide cost.

What to do: rewrite as set-based operations, use JOIN and APPLY, load relationships at once in the ORM and, in newer versions, take advantage of scalar function inlining. For N+1, the fix is in the application, which is why the DBA and the developer must work together.

10. Server configuration and maintenance

Items that look small and weigh a lot: MAXDOP and cost threshold for parallelism left at old defaults, a misconfigured recovery model and log growth, auto-shrink on, auto-close, backups at peak hours, databases on an old compatibility level.

How to diagnose: sys.configurations, each database’s properties and the job history. High CXPACKET and CXCONSUMER waits indicate badly tuned parallelism.

What to do: adjust MAXDOP and the cost threshold to the workload, turn off auto-shrink and size file growth in fixed increments, schedule maintenance in a low-load window and raise the compatibility level with testing.

A diagnostic flow we repeat

  1. Enable Query Store (ALTER DATABASE ... SET QUERY_STORE = ON) with a size limit and automatic capture.
  2. Capture wait stats at two moments, before and after the problem window, and compare the difference.
  3. List the 10 top queries by total duration and by logical reads.
  4. For each one, open the actual plan, compare estimated with actual and look for scans, spills and conversions.
  5. Fix one thing at a time and measure again. Keep the “before” to prove the result.

When the cause is outside the database

Sometimes SQL Server is innocent. The application opens too many connections, does not use a pool, pulls columns it does not need or paginates on the client. A query with no filter returns a million rows and the network and the app’s memory pay the price. Application metrics (APM) with time per query help separate slowness in the database from slowness around it.

Slow queries often surface during a platform upgrade, when a new provider changes how parameters are sent. See our guide to .NET Framework to .NET migration. If queue consumers are the ones hitting the database, our RabbitMQ .NET tutorial covers idempotent handlers that do not repeat expensive writes.

How we can help

We perform performance audits, query and index tuning, configuration reviews and SQL Server migrations, with gains measured before and after. See our SQL Server consulting expertise and our custom software development service. If slowness is hurting the business, start with the free assessment: we bring the plan of attack and the scope in weeks.

FAQ

Questions on this topic

Where do I start when SQL Server is slow?

Find out whether the slowness is one query, one time window or the whole server. Look at wait stats, the most expensive queries in Query Store and the blocked sessions at the moment of the problem. Only then change an index, a query or a setting.

Does creating every index SQL Server suggests solve it?

No. Missing-index suggestions ignore write cost, can be redundant with each other and do not consider the whole workload. Use them as a clue, evaluate the benefit on the real query and consolidate before creating.

What is parameter sniffing?

It happens when SQL Server compiles the plan with the first parameter values it receives and reuses that plan for values with a very different distribution. The plan suits one case and hurts another. Query Store helps you see plan variation and force the stable one.

Does adding memory or CPU to the server fix it?

It masks the problem for a while. If the cause is a missing index or a badly written query, more hardware postpones the problem and raises license cost. Measure first where the time is spent.

Can Query Store stay on in production?

It can and should. It is available since SQL Server 2016 and is on by default in new databases in recent versions. Set the size limit and cleanup policy, and watch the capture mode.

Tell us what you need to build.

Ask for a free assessment and get a clear path for your project, with no commitment.

Free assessment