SQL Server Performance Tuning

How We Made T-SQL Queries Run 4x Faster

Updated
2 min read
Written by
Mark Varnas

Improvement after tuning

4x

DURATION

5x

CPU

48x

DISK

Reading from disk is the slowest operation SQL Server does.

Therefore, tuning for less disk “reads” is often the target.

Problem

The stored procedure showed up in the top resource-consuming report. It was putting too much stress on the CPU.

Pre-tuning Metrics

142
Duration (ms)
157
CPU (ms)
12,805
Disk (number of reads)

Solution

To fix this issue, we added two new indexes.

Before vs. After

The improvement was significant: the total number of disk reads decreased to just 266 from 12,805, resulting in a 5x reduction in CPU time!

CPU (ms)

157
Before tuning
31
After tuning
BeforeAfterImprovement (x)
Duration (ms)*14232~4x (or 444%)
CPU (ms)*15731~5x (or 444%)
Disk (number of reads)* 12,805266~48x (or 4,814%)
*The numbers are an average of multiple T-SQL runs

Overall, we observed a staggering improvement, making the query execution 4 times faster!

Why does disk improvement matter for stored procedure speed?

It’s simple. The less you access the disk, the more disk capacity is left over.

It works just like a highway. Imagine a 3-lane highway with just 5 cars driving on it every minute.

What if you add 50 cars? The speed remains the same because 55 cars don’t overload that highway.

What if you add another 500 or 5000? Now you are starting a slowdown in traffic.

They all still get home. But not at the same speed anymore.

It’s the same deal with SQL Servers. That’s why it’s crucial to speed-tune the most critical resources.

The fewer hits to the storage, the more capacity available.

In this tuning session, better performance was achieved by overhauling a stored procedure and adding two new indexes.

As a result – 4 times faster query!

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