Plan Cache, Query Store, and Query Analysis

Using query history, cached plans, and runtime data to investigate performance.

200 associated posts60 primary posts

Performance Tuning

How to Tell if You Need More Tempdb Files

You may have read that you need to have more than one data file in SQL Server's tempdb. This can happen even if you're using blazing fast storage. If you create a lot of tiny objects in tempdb you may hit a bottleneck on special pages that SQL Server uses internally to allocate all those objects. For certain workloads, adding more tempdb files speeds up SQL Server.

Read more about How to Tell if You Need More Tempdb Files 41 comments — Join the discussion

4 Lightweight Ways to Tell if a Database is Used

We've all found those databases. They're on your production SQL Server instance, but nobody seems to know if they're being used, or what's using them.

You could run some sort of trace, but you'd probably drag down performance on your SQL Server. What you need is a quicker way to find out if the database is in use.
Is a Login Using the database?
And if so, what query did they run last? My favorite way to see this is with Adam Machanic's sp_whoisactive.

Read more about 4 Lightweight Ways to Tell if a Database is Used 52 comments — Join the discussion

Collecting Detailed Performance Measurements with Extended Events

Analyzing a workload can be difficult. There are a number of tools on the market (both free and commercial). These tools universally reduce workload analysis to totals and averages - details and outliers are smeared together. I’m against using just averages to analyze workloads; averages and totals aren’t good enough, especially with the tools we…

Read more about Collecting Detailed Performance Measurements with Extended Events 22 comments — Join the discussion
Performance Tuning

Finding One Problem Query With Extended Events

It’s easy to find problem queries on your SQL Server after they’ve happened. You can open your favorite monitoring tool or look in the plan cache. Those options are great for finding things after they’ve happened, but what if you want to find problems as they happen?
Server Side Trace
You could set up a SQL Server Server Side Trace. This is an acceptable solution if you’re using SQL Server 2008 or earlier. There are a few problems with this approach.

Read more about Finding One Problem Query With Extended Events 33 comments — Join the discussion
Performance Tuning

Exploring the Magic of the Plan Cache

The plan cache holds a lot of secrets about what’s going on inside SQL Server. In the First Responder Kit we shared one of our plan cache scripts to find the top resource consuming queries. That query works well, but over time we’ve added some additional functionality to the query. I figured it was time to share the new query that we’re using to analyze SQL Server performance.

Read more about Exploring the Magic of the Plan Cache 7 comments — Join the discussion
Performance Tuning

RECOMPILE Hints and Execution Plan Caching

When you identify that parameter sniffing is a problem, you need to test whether implementing 'recompile' hints will help plan quality. (Not sure what parameter sniffing is? Learn from this blog post or this 50 minute free video.) You must decide: what hint or command do you use, and where do you put it? What trade-offs are you making when it comes to being able to performance tune your SQL Server in the future?

Read more about RECOMPILE Hints and Execution Plan Caching 35 comments — Join the discussion

Get a Report of Your Server’s Top 10 Worst Queries

Problem: your database server’s performance stinks like Limburger cheese.

Solution: find the queries that are making that smell.
Hiding in Plain Sight
Your database server knows exactly which queries are performing the worst. When queries are executed, the execution plans – and associated execution statistics – are stored in memory (with a few exceptions). This information is stored in the plan cache, and you can access it by querying a couple of DMVs.

Read more about Get a Report of Your Server’s Top 10 Worst Queries 5 comments — Join the discussion

What?! Queries are Failing in My SQL Server?

I came across an interesting case recently where queries were failing in a high transaction SQL Server. We knew that queries were occasionally failing with error severity 20 because SQL Server Agent alerts were periodically firing. However, those built in alerts don't capture exactly what has failed-- they just say "Something failed big. Good luck with that."

Read more about What?! Queries are Failing in My SQL Server? 43 comments — Join the discussion

3 Things You Need to Stop Doing to Your Database Server

No one knows everything, especially about SQL Server. When you encounter a problem, especially for the first time, you may not know how to solve it. I’ve seen some crazy approaches taken to fix problems – like duct tape on a car. Many times, instead of fixing the root cause of a problem, such as a poorly-performing query, a server-level change is made.

Read more about 3 Things You Need to Stop Doing to Your Database Server 1 comment — Join the discussion

SQL Server Management Studio: “Include Client Statistics” Button

I’m curious. I like to know how things work. I have to read the user manual of everything I buy so I know all of its features. I like clicking all the buttons in applications I work with. However, SQL Server Management Studio (SSMS) has so many I haven’t gotten through all of them. At SQL Saturday #118 Wisconsin earlier this year, I was watching a presentation and the presenter clicked “Include Client Statistics”.

Read more about SQL Server Management Studio: “Include Client Statistics” Button 14 comments — Join the discussion
Performance Tuning

Introducing the SQL Server Plan Cache (and a Better sp_Blitz®)

When you send your beautifully hand-crafted organic T-SQL statement to SQL Server, the database engine takes a moment to appreciate the poetry of your work.  Before it turns your request into results, it has to build an execution plan.  SQL Server considers: Which tables it needs to join together What subqueries it needs to execute…

Read more about Introducing the SQL Server Plan Cache (and a Better sp_Blitz®) 22 comments — Join the discussion

The Use and Abuse of RECOMPILE in SQL Server (Video)

What are the costs when you ask SQL Server to recompile a statement or a stored procedure each time it runs? In this 30 minute talk Kendra Little explains the impact on query execution-- and on your SQL Server instance-- of forcing recompilation. This talk is appropriate for DBAs and Developers who have a working knowledge of execution plans in SQL Server.

Read more about The Use and Abuse of RECOMPILE in SQL Server (Video) 8 comments — Join the discussion

SQL Server First Responders Kit Video

When your SQL Server is critically injured you need a first responder kit to help you diagnose the problem and apply emergency aid. In this session, Kendra Little introduces you to invaluable tools and techniques for triaging an emergency. If you have one year’s experience with database administration, this half-hour session will set you up to triage like a pro.

Read more about SQL Server First Responders Kit Video 7 comments — Join the discussion

How to Use sp_WhoIsActive to Find Slow SQL Server Queries

SQL Server database administrators need to be able to quickly find out what queries and stored procedures are running slow.  Microsoft includes sp_who and sp_who2 in SQL Server 2005 and 2008, but there's a much better tool, and it's completely free.

In this five minute tutorial video, I explain how to use sp_WhoIsActive from Adam Machanic (Blog - @AdamMachanic):

Read more about How to Use sp_WhoIsActive to Find Slow SQL Server Queries Be the first to comment