SQL Server Performance Tuning

How We Made T-SQL Queries Run 354 Times Faster

Updated October 29, 20253 min read

Written byMark Varnas

Improvement after tuning

43xDURATION
144xCPU
168xDISK

Reading from disk is the slowest operation SQL Server does.

Therefore, tuning for less disk “reads” is often the primary goal.

Problem

The stored procedure ran very frequently (multiple times per minute) and consumed a lot of server resources (CPU, Disk reads and Duration).

Pre-tuning Metrics

44,177
Duration (ms)
64,829
CPU (ms)
686,140
Disk (number of reads)

Solution

We added certain indexes to improve the performance.

Before vs. After

There was a dramatic improvement: the overall duration of the procedure plummeted from 44,177 ms to only 1,037 ms!

Here's a comparison highlighting the gains in efficiency:

Query performance: before and after tuning

We took 5 separate runs to analyze query performance before and after the fix:

Duration (ms)CPU (ms)Disk (8k page reads)
BeforeAfterBeforeAfterBeforeAfter
Run 137,06139164,446281932,2043,687
Run 244,00221866,730203633,6202,658
Run 344,5842,81166,403765617,2824,395
Run 442,81982162,434515617,1623,613
Run 552,42294664,134484630,4336,067
AVG44,1771,03764,829449686,1404,084

As you can see, we successfully cut down on the average number of disk reads:

Disk, number of reads (average)

686,140
Before tuning
4,084
After tuning

Before TunningAfter TunningImprovement (%)Improvement (x)
Duration (ms)*44,1771,0374,26043
CPU (ms)*64,82944914,439144
Disk (number of operations)*686,1404,08416,801168
*The numbers Before/After are an average of 5 separate procedure runs

Overall, we observed a staggering improvement, making the query execution 354 times faster!

Final thoughts

Most SQL Servers bottleneck is on Disk access (or disk “reads”).

It’s not CPU or RAM – which most customers often suspect first.

And that makes much sense. Here is why:

  • Inefficient queries scan (or read) much data.
  • Data read in is stored in RAM. As more data is read in, “older” data is pushed out from RAM.
  • If the available RAM isn't sufficient to hold all data in memory (a common scenario), SQL Server must resort to disk reads, which are the slowest operations it can perform.
  • When the query can be tuned to read 10 rows vs. 10 million – less CPU and RAM automatically are necessary.

Since 95% of SQL Server bottlenecks are due to disk resources, cutting down on disk reads is the main goal.

To the end-user, nothing is more important than Speed (or Duration of the query), in any case.

Tuning to lower CPU/RAM usage is also beneficial.

When queries are tuned to need less CPU & RAM, it means that the same server now has more capacity.

Discover More

Discover what clients are saying about Red9

Red9 has incredible expertise both in SQL migration and performance tuning.

The biggest benefit has been performance gains and tuning associated with migrating to AWS and a newer version of SQL Server with Always On clustering. Red9 was integral to this process. The deep knowledge of MSSQL and combined experience of Red9 have been a huge asset during a difficult migration. Red9 found inefficient indexes and performance bottlenecks that improved latency by over 400%.

Rich StaatsRich StaatsCloud EngineerMetalToad
See more testimonials