Finance operations
~105 GBless data read on every run
Every run of this receipts-repair procedure waited about 31 seconds (30,682 ms). Splitting one query with UNION cut that to 685 ms.
Data read per run
Source: average of multiple runs. Data = 12,850,589 → 18,532 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 stored procedure was too slow and performed too many disk reads.
Here’s a glance at the pre-tuning metrics:
- Duration (ms): 30,682
- CPU (ms): 18,922
- Disk (number of read operations): 12,850,589
The fix
This is what we did to fix the issue: a SELECT with four JOINS became two SELECTs using a UNION.
That’s it.
Final thoughts
Most SQL Server performance issues come from disk access, not the CPU or RAM as often thought.
The main problem is disk reads due to inefficient queries that fill up RAM and push the system to read from the disk - its slowest operation.
We boosted performance by turning a
SELECTwith fourJOINSinto twoSELECTs with aUNION, simplifying queries to reduce system load and directly enhance speed.
This approach makes queries more efficient and decreases disk reads, thereby lightening the load on both CPU and RAM.
Cutting down on disk reads is key because it directly improves SQL Server's main performance issue, leading to faster query times.
Under the hood
Before and after, every measurement
The improvement was huge: the total number of disk reads was 18,532 instead of 12,850,589!
We can't paste the client code here, but here is what we can show you.
Below you will see a comparison of SQL procedure performance before and after tuning.

| Before | After | Improvement | |
|---|---|---|---|
| Duration (ms)* | 30,682 | 685 | 45x |
| CPU (ms)* | 18,922 | 1,249 | 15x |
| Disk (number of read operations)* | 12,850,589 | 18,532 | 693x |
[RepairPostedReceiptsOnVoidedEntries] runs.After our tuning, the stored procedure became significantly faster, with average duration dropping from 30,682 ms to 685 ms.
That’s ~45x faster.


