SQL Server Performance Tuning

How Indexes Made a Constantly Running Procedure 43x Faster

Updated October 29, 20253 min read

Money: licensing capacity freed

~$1,900a year of SQL Server licensing capacity freed (conservative estimate)

It ran several times a minute and used about 65 seconds of CPU per run on average. At just 2 runs a minute, the fix frees about 51 CPU-hours a day: the full-time work of about 2 cores.

CPU time per day (at 2 runs a minute)

Before~52 h
After~0.4 h

Conservative estimate. CPU saved: (65 s − 0.45 s) × 2 runs a minute × 1,440 minutes = ~51.5 CPU-hours a day ÷ 24 = ~2.1 cores. Priced at Microsoft’s SQL Server 2022 Standard pay-as-you-go list rate, $73 per core per month (Enterprise, at $274, would be ~$7,100). The post says “multiple times per minute”; 2 is the low end. Freed capacity turns into savings when the server is sized down or an upgrade is avoided.

Reading from disk is the slowest operation SQL Server does.

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

The problem

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

The fix

We added certain indexes to improve the performance.

Final thoughts

The bottleneck for most SQL Servers is 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.

Disk is one of the most common SQL Server bottlenecks, so 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.

Under the hood

Before and after, every measurement

There was a dramatic improvement: the overall duration of the procedure plummeted from 44.2 seconds (44,177 ms) to just over 1 second (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:

Before TuningAfter TuningImprovement
Duration (ms)*44,1771,03743x
CPU (ms)*64,829449144x
Disk (number of operations)*686,1404,084168x
*The numbers Before/After are an average of 5 separate procedure runs

Overall, the procedure ran 43 times faster.

CPU time dropped 144 times and disk reads dropped 168 times.

Check Red9's SQL Server Services

SQL Server Consulting

Perfect for one-time projects like SQL migrations or upgrades, and short-term fixes such as performance issues or SQL remediation.

Discover More ➜

SQL Server Managed Services

Continuous SQL support, proactive monitoring, and expert DBA help with one predictable monthly fee.

Discover More ➜

Emergency SQL Support

Take the stress out of emergencies with immediate access to a SQL Server Sr. DBA 24x7x365

Discover More ➜

Explore All Services ➜