What Do You Do When Performance Sucks?

Guy-Glantser, 2017-05-16

 

So you are a SQL Server DBA, and you are responsible for a database, which gives you a hard time. Users constantly complain about poor performance, and the developers blame the database (what else?). It’s time to dig in and do some serious performance tuning once and for all. But how? Where do you start?

 

First, you need to identify the most heavy queries that run in your database. You can find them in two ways. The first is to monitor query statistics using DMVs, and the second is to run an event session or a SQL trace for a period of time, and collect “Statement Completed” events. Each method has its own pros and cons, but both of them can lead you to the most heavy queries in your database.

 

Once you have a problematic query in your hand, you need to execute it and examine its actual execution plan. That would probably mean executing the query in SQL Server Management Studio (SSMS). At this point, you have to be aware to an issue with the setting of ARITHABORT, which is different by default between the application and SSMS. This is a very common pitfall, which might lead you in the wrong direction and result in a lot of frustration.

 

The next step in your performance tuning journey is to analyze the actual execution plan of the query (the correct one) and find the bottlenecks in it. There are many things you need to know about execution plan analysis. But where do you begin? A common mistake is to begin with the operator with the highest relative cost. This is wrong for several reasons. The main reason is that the cost is always estimated, even when you look at the actual plan. And in most cases, the reason for the performance problem is poor estimations, so the cost numbers are probably lying to you. The right place to begin your execution plan analysis is to compare the estimated vs. actual number of rows in the various operators. If you find a big gap between the estimated and the actual number of rows, then there is a good chance that this is the reason for the performance issue, and now all you need to do is to understand why and fix it.

 

There can be all kinds of reasons for poor estimations, such as parameter sniffing, use of table variables or outdated statistics. Each one has its own remedies and solutions. For example, if the problem is outdated statistics, then you can update statistics more often, use filtered statistics, use trace flag 2371 (or upgrade to SQL Server 2016), etc. You can also instruct the optimizer how to execute the query by using query hints or plan guides. But you should be very careful with these tools, as they might constrain the optimizer and cause poor plans in the future in ways that you didn’t expect.

 

An important aspect of performance tuning is measuring. You have to be consistent about how you measure performance. If you change something in order to improve performance – how do you know if it really helped? Maybe it made things worse. And if it helped, by how much? Does it have a meaningful impact or is it a small change that users don’t even realize. Sometimes, you might change something that really improves the query at hand, but at the same time degrades performance of other queries. So you need a consistent and reliable method for measuring query performance, and use it in order to benchmark your changes.

 

This is such an important topic, and there is so much to cover. This is why I created the Advanced Query Tuning in SQL Server online course. In this course I go into details about all the things I mentioned here, and more, with extensive demos that you can download and play with. This course will take you many steps forward in your performance tuning journey and make you a query tuning professional. Pay only once, and get a lifetime access to the course.

 

Are you ready for it?

 

The post What Do You Do When Performance Sucks? appeared first on Madeira Data Solutions.

Rate

Share

Share

Rate

Related content

Database Mirroring FAQ: Can a 2008 SQL instance be used as the witness for a 2005 database mirroring setup?

Question: Can a 2008 SQL instance be used as the witness for a 2005 database mirroring setup? This question was sent to me via email. My reply follows. Can a 2008 SQL instance be used as the witness for a 2005 database mirroring setup? Databases to be mirrored are currently running on 2005 SQL instances but will be upgraded to 2008 SQL in the near future.

Robert Davis

2009-02-23

1,567 reads

Networking – Part 4

You may want to read Part 1 , Part 2 , and Part 3 before continuing. This time around I’d like to talk about social networking. We’ll start with social networking. Facebook, MySpace, and Twitter are all good examples of using technology to let…

Andy Warren

2009-02-17

1,530 reads

Speaking at Community Events – More Thoughts

Last week I posted Speaking at Community Events – Time to Raise the Bar?, a first cut at talking about to what degree we should require experience for speakers at events like SQLSaturday as well as when it might be appropriate to add additional focus/limitations on the presentations that are accepted. I’ve got a few more thoughts on the topic this week, and I look forward to your comments.

Andy Warren

2009-02-13

360 reads