SQL Server Performance Tuning

How We Boosted SQL Server Performance to Run 51 Times Faster

Updated October 29, 20255 min read

Written byMark Varnas

Duration improvement after tuning

41xQUERY #1
2xQUERY #2
8xQUERY #3

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

Problem

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

Solution

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

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

Query #2.UPDATE bins set bin_flag=1:
Created index IX__bin_flag__INC on [<removed>_ldbld_bins]

Query #3. Tuning procedure <removed>_DealerPortal_UpdateCustomerLevel:
Replace two temporary tables with Common Table Expressions (CTE)

Before vs. After

Query #1

[simple_chart type="bar" name="Query 1" labels="Duration (ms), CPU (ms)" data="164,83" label="Before" color="#e32a24" border="#000fff" data_1="4, 15" label_1="After" color_1="#2b2d42" options="plugins: {title: {display: true,text: 'Query #1, improvement before/after tuning', position:'top'}}"]
Duration
(ms)
CPU
(ms)
Disk
(8k page reads)
BeforeAfterBeforeAfterBeforeAfter
Run 120349316943601
Run 212547315592601
AVG16448315767601
BeforeAfterImprovement
Duration (ms)*164441x (or 4,100%)
CPU (ms)*83155,53x (or 553%)
Disk (number of reads)*7676011,28x (or 128%)
*The numbers are an average of multiple runs of the query: SELECT oeh.user_def_field...

Query #2

[simple_chart type="bar" name="Query 2" labels="Duration (ms), CPU (ms)" data="43,39" label="Before" color="#e32a24" border="#000fff" data_1="21, 15" label_1="After" color_1="#2b2d42" options="plugins: {title: {display: true,text: 'Query #2, improvement before/after tuning', position:'top'}}"]
Duration
(ms)
CPU
(ms)
Disk
(8k page reads)
BeforeAfterBeforeAfterBeforeAfter
Run 144214716979985
Run 2492747151,003985
Run 341213116991985
Run 4391731161,012985
AVG43213915996985
BeforeAfterImprovement
Duration*43212,05x (or 205%)
CPU*39152,6x (or 260%)
Disk*9969851,01x (or 101%)
*The numbers are an average of multiple runs of the query: UPDATE bins set bin_flag=1...

Query #3

[simple_chart type="bar" name="Query 3" labels="Duration (ms), CPU (ms)" data="1075,67" label="Before" color="#e32a24" border="#000fff" data_1="134, 10" label_1="After" color_1="#2b2d42" options="plugins: {title: {display: true,text: 'Query #3, improvement before/after tuning', position:'top'}}"]
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 (or 802%)
CPU*6716~7x (or 670%)
Disk*323111~3x (or 291%)
*The numbers are an average of multiple runs of the query: [redacted]_DealerPortal_UpdateCustomerLevel

In a nutshell, by tweaking these three queries, we slashed the total execution time (Duration) by a whopping 51 times!

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.

Discover More

Discover what clients are saying about Red9

Red9 has incredible expertise both in SQL migration and performance tuning.

The biggest benefit has been performance gains and tuning associated with migrating to AWS and a newer version of SQL Server with Always On clustering. Red9 was integral to this process. The deep knowledge of MSSQL and combined experience of Red9 have been a huge asset during a difficult migration. Red9 found inefficient indexes and performance bottlenecks that improved latency by over 400%.

Rich StaatsRich StaatsCloud EngineerMetalToad
See more testimonials