SQL Server Performance Tuning

How We Made T-SQL Queries Run 678 Times Faster

Updated October 29, 20253 min read

Written byMark Varnas

Improvement after tuning

108xDURATION
109xCPU
462xDISK

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 was too slow and performed an excessive amount of disk reads, as shown in the chart below:

Pre-tuning metrics (average of 5 separate runs)

31,025
Duration (ms)
30,659
CPU (ms)
7,929,279
Disk (number of reads)

Solution

Here's what we did to fix the issue:

  • Split a subquery into four parts using UNION
  • Replaced ISNULL function in WHERE clause

That’s it. That simple.

Before vs. After

The improvement was huge: average duration dropped from 31,025 ms to just 287 ms!

Below you will see a comparison of SQL procedure performance before and after tuning.

Microsoft SQL performance tuning chart

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

Duration (ms)CPU (ms)Disk
(8k page reads)
BeforeAfterBeforeAfterBeforeAfter
Run 174,23748073,3284698,189,92028,724
Run 221,59230621,4222977,877,02319,023
Run 318,81516018,6251567,851,2099,542
Run 422,21432721,9063287,877,04819,023
Run 518,26816518,0161567,851,1969,539
AVG31,02528730,6592817,929,27917,170

We managed to significantly reduce the total number of disk reads:

Disk, number of reads(average)

7,929,279
Before tuning
17,170
After tuning
BeforeAfterImprovement (%)Improvement (x)
Duration, ms*31,02528710,810108
CPU, ms*30,65928110,911109
Disk, number of reads*7,929,27917,17046,181462
Overall improvement67,901%679x

After our tuning, the stored procedure became many times faster, showing an overall improvement of 67,901%!

That’s 678x faster!

Why does disk improvement matter for stored procedure speed?

It's straightforward: the less often you access the disk, the more disk capacity remains available.

It works just like a highway. Imagine a 3-lane highway with just 5 cars driving on it every minute.

What if you add 50 cars? The speed remains the same because 55 cars don’t overload that highway.

What if you add another 500 or 5000? Now you are starting a slowdown in traffic.

They all still get home. But not at the same speed anymore.

It's the same deal with SQL Servers. That's why it's crucial to speed-tune the most critical resources.

The fewer hits to the storage, the more capacity available.

During this tuning, we achieved improved performance by dividing a subquery into four distinct parts through UNION and substituting the ISNULL function in the WHERE clause.

As a result - 678 times faster query!

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