Category: Execution Plans

Performance Tuning

What’s New in SQL Server 2019: Adaptive Memory Grants

When you run a query, SQL Server guesses how much memory you're going to need for things like sorts and joins. As your query starts, it gets an allocation of workspace memory, then starts work. Sometimes SQL Server underestimates the work you're about to do, and doesn't grant you enough memory. Say you're working with…

Read more about What’s New in SQL Server 2019: Adaptive Memory Grants 3 comments — Join the discussion
Performance Tuning

A Simple Stored Procedure Pattern To Avoid

Get Yourself Together
This is one of the most common patterns that I see in stored procedures. I'm going to simplify things a bit, but hopefully you'll get enough to identify it when you're looking at your own code.

Here's the stored procedure:
[crayon-6a6eb98422c90792424334/]
There's a lot of perceived cleverness in here.

Read more about A Simple Stored Procedure Pattern To Avoid 15 comments — Join the discussion
Performance Tuning

Should You Use the New Compatibility Modes and Cardinality Estimator?

For years, when you right-clicked on a database and click Properties, the "Compatibility Level" dropdown was like that light switch in the hallway: You would flip it back and forth, and you didn't really understand what it was doing. Lights didn't go on and off. So after flipping it back and forth a few times,…

Read more about Should You Use the New Compatibility Modes and Cardinality Estimator? 13 comments — Join the discussion
Performance Tuning

Forwarded Fetches and Bookmark Lookups

Base Table
When you choose to forgo putting  a clustered index on your table, you may find your queries utilizing forwarded fetches -- SQL Server's little change of address form for rows that don't fit on the page anymore.

This typically isn't a good thing, though. All that jumping around means extra reads and CPU that can be really confusing to troubleshoot.

Read more about Forwarded Fetches and Bookmark Lookups 4 comments — Join the discussion
Performance Tuning

Is the CXCONSUMER Wait Type Harmless? Not So Fast, Tiger.

Let's say you've got a query, and the point of that query is to take your largest customer/user/whatever and compare their activity to smaller whatevers. If SQL Server doesn't balance that work evenly across multiple threads, you can experience the CXCONSUMER and/or CXPACKET wait types. To show how SQL Server ends up waiting, let's write…

Read more about Is the CXCONSUMER Wait Type Harmless? Not So Fast, Tiger. 8 comments — Join the discussion
Performance Tuning

A Surprising Simplification Limitation

When It Comes To Simplification Rob Farley has my favorite material on it. There's an incredible amount of laziness ingenuity built into the optimizer to keep your servers from doing unnecessary work. That's why I'd expect a query like this to throw away the join: [crayon-6a6eb98427d0c564936778/] After all, we're joining the Users table to itself…

Read more about A Surprising Simplification Limitation 16 comments — Join the discussion