Live classes start in 2d 23h 32m — Save your seat

Category: Execution Plans

Performance Tuning

How to Think Like the SQL Server Engine: What’s the Tipping Point?

In our last episode, I'd expanded our query to include DisplayName and Age - two columns that weren't in our nonclustered index: [crayon-6ae4631db9a68336780653/] So as a result, I was getting key lookups in the execution plan: And I spent a lot of time talking about the overhead that each key lookup incurs. Astute readers among…

Read more about How to Think Like the SQL Server Engine: What’s the Tipping Point? 5 comments — Join the discussion
Performance Tuning

DBA Training Plan 13: Why Do Cached Plans Go Bad?

It's a little bit of a trick question: what could make a good query plan turn bad?

In the last episode, we used sp_BlitzCache to spot the most resource-intensive, longest-running query plans in your server's cache. Go run those queries again, right now, and I bet you're going to see plans in the cache that use parameters. Maybe they're stored procedures, or maybe they're parameterized SQL.

Read more about DBA Training Plan 13: Why Do Cached Plans Go Bad? 2 comments — Join the discussion
Performance Tuning

Research Paper Week: Plan Stitch: Harnessing the Best of Many Plans

Those of you who follow me on Instagram, Twitter, or Facebook know I'm taking most of August off for vacation. Erika and I spent the last couple of weeks in Telluride, had a brief stop in Sacramento for SQL Saturday, and this week we're touring wineries in Napa and Sonoma. As part of recharging, I…

Read more about Research Paper Week: Plan Stitch: Harnessing the Best of Many Plans 6 comments — Join the discussion
Performance Tuning

DBA Training Plan 12: What Query Plans Are In Cache?

In the last episode, while talking about the basics of executing queries, I said that SQL Server caches execution plans in memory, reusing them whenever the same query gets executed again. I've also talked about the dynamic management views (DMVs) that let you query what's in SQL Server's memory. Let's put those two things together and find out what queries have been running on the server lately.

Read more about DBA Training Plan 12: What Query Plans Are In Cache? 5 comments — Join the discussion
Performance Tuning

DBA Training Plan 11: The Basics of Executing a Query

Up til now in the DBA Training Plan, we've been taking inventory of our servers, making sure the data's well-protected, and understanding the basics of how the data's stored in indexes inside those data files. Now, let's start looking at performance, and let's start by zooming really far out to think about how SQL Server runs a query.

Read more about DBA Training Plan 11: The Basics of Executing a Query 13 comments — Join the discussion
Performance Tuning

Why Order Isn’t Guaranteed Without an ORDER BY

Start with the Stack Overflow database, with no nonclustered indexes. If you've been playing around with demos, run my DropIndexes proc just to clear things out, which leaves the clustered indexes in place.

Say you run this query:
[crayon-6ae4631dc790c988300213/]
By default, with a clustered index on the Id field (identity, starts at 1 and goes up to a bajillion), your results will probably look like this, ordered by Id:

Read more about Why Order Isn’t Guaranteed Without an ORDER BY 9 comments — Join the discussion
Performance Tuning

Finding Froid’s Limits: Testing Inlined User-Defined Functions

This week, I've been writing about how SQL Server 2019's bringing a few new features to mitigate parameter sniffing, but they're more complex than they appear at first glance: adaptive memory grants, air_quote_actual plans, and adaptive joins. Today, let's talk about another common cause of wildly varying durations for a single query: user-defined functions.

Read more about Finding Froid’s Limits: Testing Inlined User-Defined Functions 16 comments — Join the discussion
Performance Tuning

Parameter Sniffing in SQL Server 2019: Adaptive Joins

So far, I've talked about how adaptive memory grants both help and worsen parameter sniffing, and how the new air_quote_actual plans don't accurately show what happened. But so far, I've been using a simple one-table query - let's see what happens when I add a join and a supporting index:
[crayon-6ae4631dc93b6044364857/]
(Careful readers will note that I'm using a different reputation value than I used in the last posts - hold that thought. We'll come back to that.)

Read more about Parameter Sniffing in SQL Server 2019: Adaptive Joins 1 comment — Join the discussion
Performance Tuning

Parameter Sniffing in SQL Server 2019: Air_Quote_Actual Plans

My last post talked about how parameter sniffing caused 3 problems for a query, and how SQL Server 2019 fixes one of them - kinda - with adaptive memory grants.

However, the post finished up by talking about how much harder performance troubleshooting will be on 2019 because your query's memory grant is based on the last set of parameters used, not the current set.

Read more about Parameter Sniffing in SQL Server 2019: Air_Quote_Actual Plans Be the first to comment
Performance Tuning

Parameter Sniffing in SQL Server 2019: Adaptive Memory Grants

This week, I'm demoing SQL Server 2019 features that I'm really excited about, and they all center around a theme we all know and love: parameter sniffing.

If you haven't seen me talk about parameter sniffing before, you'll probably wanna start with this session from SQLDay in Poland. This week, I'm going to be using the queries & discussion from that session as a starting point.

Read more about Parameter Sniffing in SQL Server 2019: Adaptive Memory Grants 18 comments — Join the discussion
Performance Tuning

Never Judge A Query By Its Cost

Signs and Numbers
When tuning queries, or even finding queries to tune, there's a rather misguided desire to look for queries with a high cost, or judge improvement by lowering query cost. The problem is that no matter what you're looking at, costs are estimates, and often don't reflect how long a query runs for or the actual work involved in processing the query.

Read more about Never Judge A Query By Its Cost 7 comments — Join the discussion
Performance Tuning

“Surely this one will get a clustered index scan.”

I love building demos for our training classes because I'm constantly in a battle of the minds with SQL Server. I try to guess what he's going to do next, and I love it when he surprises me.

I started by building a new parameter sniffing demo with the Stack Overflow database, and in this case using the 50GB 2013 size. I wanted to demo a search stored procedure looking for the first few words of question titles.

Read more about “Surely this one will get a clustered index scan.” 25 comments — Join the discussion