SQL Server Performance Tuning

How We Boosted SQL Server Performance to Run 51 Times Faster

Updated
3 min read
Written by
Mark Varnas

Duration improvement after tuning

41x

QUERY #1

2x

QUERY #2

8x

QUERY #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

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

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

Duration
(ms)
CPU
(ms)
Disk
(8k page reads)
BeforeAfterBeforeAfterBeforeAfter
Run 1584149471632576
Run 21,2901803116325130
Run 31,35273125320129
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.

Article by
Mark Varnas
Founder | CEO | SQL Veteran
Hey, I'm Mark, one of the guys behind Red9. I make a living performance tuning SQL Servers and making them more stable.

Managed SQL Server services, consulting, and emergency support from expert DBAs to improve performance, predictability, and cost.

Get started with Red9 today.

Contact us

Discover More

SQL Server Health Check SQL Server Migrations & Upgrades SQL Server Performance Tuning SQL Server Security SQL Server Tips

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 Staats 5 stars
Rich Staats
Cloud Engineer
MetalToad

Always willing to go an extra mile

Working with Red9 DBAs has been a pleasure. They are great team players and have an expert knowledge of SQL Server database administration. And are always willing to go the extra mile to get the project done.
5 stars
Evelyn A.
Sr. Database Administrator

Boosts server health and efficiency for enhanced customer satisfaction

Since adding Red9 to the reporting and DataWarehousing team, Red9 has done a good job coming up to speed on our environments and helping ensure we continue to meet our customer's needs. Red9 has taken ownership of our servers ensuring they remain healthy by monitoring and tuning inefficient queries.
5 stars
Andrew F.
Datawarehousing Manager
See more testimonials