Server load
~168 MBless data read on every run
Loading a team’s shade masks took 180 ms per call. A cursor option, a table variable and one index cut that to 23 ms.
Data read per run
Source: 5 runs before and after.
Reading from disk is the slowest operation SQL Server does.
Therefore, tuning for less disk “reads” is often the primary goal.
The problem
The slow stored procedure significantly hampered SQL Server performance.
The fix
So here's what we did to improve the query performance:
- Changed cursor type to
FAST_FORWARD - Replaced temporary
#tablewith variable@table - Added index
IX_groupID_IsDeletedondbo.Infractions
Final thoughts
If possible, avoid cursors!
Under the hood
Before and after, every measurement
The most interesting part…
The improvement was significant: the total number of disk reads decreased to just 1,271 from 21,737, resulting in a 5x reduction in CPU time!
The green block below shows SQL performance numbers after we made some changes in the database to improve slow SQL calls.

We took 5 separate runs to analyze query performance before and after the fix:
| Duration (ms) | CPU (ms) | Disk (8k page reads) | ||||
|---|---|---|---|---|---|---|
| Before | After | Before | After | Before | After | |
| Run 1 | 218 | 11 | 171 | 16 | 23,265 | 34 |
| Run 2 | 71 | 18 | 79 | 15 | 17,608 | 1,073 |
| Run 3 | 301 | 4 | 110 | 16 | 23,040 | 100 |
| Run 4 | 208 | 19 | 156 | - | 23,841 | 773 |
| Run 5 | 106 | 67 | 109 | 47 | 20,935 | 4,376 |
| AVG | 180 | 23 | 125 | 24 | 21,737 | 1,271 |
| Before | After | Improvement | |
|---|---|---|---|
| Duration (ms)* | 180 | 23 | ~8x |
| CPU (ms)* | 125 | 24 | ~5x |
| Disk (number of reads)* | 21,737 | 1,271 | ~17x |
After our tuning, the stored procedure became significantly faster, with average duration dropping from 180 ms to 23 ms.
That’s about 8x faster.
I still see a lot of people using cursors when they shouldn’t.
There are very few situations where a set-based query cannot replace cursor logic.
For these, a FAST_FORWARD cursor is an excellent place to start.
Cursor options like FORWARD_ONLY, STATIC, and KEYSET can all produce parallel plans and reduce performance impacts too.


