SQL Server Performance Tuning

How Reading Fewer Rows Made a Billing Procedure 9x Faster

Updated October 29, 20253 min read

Billing operations

~26 GBless data read on every billing run

Every billing run waited 34 seconds while the procedure hauled millions of rows it did not need. Now it takes under 4.

Data read per run

Before27 GB
After1.2 GB

Source: 3 runs before and after. Data = 3,298,493 → 147,424 pages × 8 KB.

Reading from disk is the slowest operation SQL Server does.

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

The problem

The client's billing process was slow because the stored procedure took 34.3 seconds (34,256 ms) on average to run.

Profiler trace before tuning: three runs of the stored procedure at 33,200 to 35,998 ms and about 3.3 million reads each
Figure 1 - Pre-tuning stored procedure stats

Here’s a glance at the pre-tuning metrics:

  • Duration (ms): 34,256
  • CPU (ms): 33,968
  • Disk (number of read operations): 3,298,493

The fix

This stored procedure was slow due to the large number of disk reads it was performing.

We refactored the code to reduce the number of reads it needed to perform.

Instead of hauling millions of rows, we trimmed it down to just what was needed.

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 there isn’t enough RAM to keep ALL data in memory (which is often not possible), SQL Server has to read from disk, and that is the slowest operation SQL Server can do.
  • 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).

Tuning to reduce CPU/RAM resources is helpful too.

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

The most interesting part...

Here's the before-and-after snapshot that showcases the efficiency gains:

Figure 2 - Performance of the SP after tuning
Figure 2 - Post-tuning stored procedure performance

Disk reads took a massive dive, plummeting from 3,298,493 down to just 147,424.

That's more than a 22-fold decrease!

Here is the breakdown:

BeforeAfterImprovement
Duration (ms)*34,2563,859~9x
CPU (ms)*33,9683,854~9x
Disk (number of read operations)*3,298,493147,424~22x
*The numbers Before/After are an average of 3 separate procedure runs

After our tuning, the stored procedure became significantly faster, with average duration dropping from 34.3 seconds (34,256 ms) to 3.9 seconds (3,859 ms).

That's almost 9x faster.

That means that through refactoring, we've reduced the overall duration time from 34.3 seconds to just 3.9 seconds!

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 ➜