SQL Server Performance Tuning

How We Made 3 Slow SQL Queries Up to 41x Faster

Updated October 29, 20253 min read

Partner and user experience

~940 msless waiting per partner tier update

Partners updating their account tier waited 1,075 ms on average. Now they wait 134 ms, and all three fixed queries use 2.6–5.5x less CPU.

Milliseconds per run

BeforeAfter

Partner-portal tier update

Before: 1,075 ms
After: 134 ms

UPDATE

Before: 43 ms
After: 21 ms

Source: averages of 2–4 runs per query.

Tuning SQL Server to cut down on CPU time and disk read operations makes everything run smoother and faster, boosting both performance and reliability.

The problem

Three slow stored procedures significantly affected the SQL Server's performance.

The fix

Here is what we did to make these queries run much faster:

Query #1. SELECT that runs every 30 minutes:
Created index [IX_ref_4__INC] on [ordhdrlog_sql]

Query #2. UPDATE:
Created index IX__bin_status__INC on [whs_load_bins]

Query #3. Tuning procedure PartnerPortal_UpdateAccountTier:
Replace two temporary tables with Common Table Expressions (CTE)

Final thoughts

When you tune SQL Server to use less CPU time, you're basically giving your server a break, letting it do more work with less effort.

This means your queries fly faster, and you can get more done at once without the server breaking a sweat.

Plus, it's a win for your budget too, because your hardware lasts longer and runs smoother.

Under the hood

Before and after, every measurement

Query #1

Per run, before and after

BeforeAfter

Duration41x less

Before: 164 msAfter: 4 ms

CPU time5.53x less

Before: 83 msAfter: 15 ms

Disk reads1.28x less

Before: 767 readsAfter: 601 reads

Each pair of bars is on its own scale.

Duration
(ms)
CPU
(ms)
Disk
(8k page reads)
BeforeAfterBeforeAfterBeforeAfter
Run 120349316943601
Run 212547315592601
AVG16448315767601
BeforeAfterImprovement
Duration (ms)*164441x
CPU (ms)*83155.53x
Disk (number of reads)*7676011.28x
*The numbers are an average of multiple runs of the query: SELECT...

Query #2

Per run, before and after

BeforeAfter

Duration2.05x less

Before: 43 msAfter: 21 ms

CPU time2.6x less

Before: 39 msAfter: 15 ms

Disk reads1.01x less

Before: 996 readsAfter: 985 reads

Each pair of bars is on its own scale.

Duration
(ms)
CPU
(ms)
Disk
(8k page reads)
BeforeAfterBeforeAfterBeforeAfter
Run 144214716979985
Run 2492747151,003985
Run 341213116991985
Run 4391731161,012985
AVG43213915996985
BeforeAfterImprovement
Duration*43212.05x
CPU*39152.6x
Disk*9969851.01x
*The numbers are an average of multiple runs of the query: UPDATE...

Query #3

Per run, before and after

BeforeAfter

Duration~8x less

Before: 1,075 msAfter: 134 ms

CPU time~4x less

Before: 67 msAfter: 16 ms

Disk reads~3x less

Before: 323 readsAfter: 111 reads

Each pair of bars is on its own scale.

Duration
(ms)
CPU
(ms)
Disk
(8k page reads)
BeforeAfterBeforeAfterBeforeAfter
Run 1584149471632576
Run 21,2901803116325130
Run 31,35273125-320129
AVG1,0751346716323111
BeforeAfterImprovement
Duration*1,075134~8x
CPU*6716~4x
Disk*323111~3x
*The numbers are an average of multiple runs of the query: PartnerPortal_UpdateAccountTier

In a nutshell, the first query now runs 41 times faster.

The other two run 2 times and 8 times faster.

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 ➜