Execution Strategies and Runtime Behavior

Joins, parallel execution, memory grants, spills, and adaptive execution.

93 associated posts89 primary posts

How to Think Like the SQL Server Engine: The Perils of SELECT *

In our last post, we ran a query with an ORDER BY, but we only got one column in the SELECT:
[crayon-6a707eef6df77303371146/]
The estimated cost was about $18 Query Bucks because SQL Server had to:

Scan the entire clustered index, yelling out the Id and LastAccessDate of each row
Sort that list by LastAccessDate

Read more about How to Think Like the SQL Server Engine: The Perils of SELECT * 5 comments — Join the discussion

[Video] What’s New in SQL Server 2019

We must be getting pretty close to the official release of Microsoft SQL Server 2019. There are less than 80 days left in the year. (Interestingly, it's been almost 60 days since Release Candidate 1 shipped - that's unusually long for a delay between builds. Hmm.)

With the clock ticking down, now's a good time to take a 40-minute look at some of my favorite new features: deferred compilation for table variables, adaptive memory grants, adaptive joins, and air_quote_actual plans:

Read more about [Video] What’s New in SQL Server 2019 20 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
T-SQL & Development

User-defined scalar functions suck – even when they don’t access data.

The performance of scalar functions sucks hard. Let's see it in action using the Stack Overflow database - any size will work. I'll set things up first in case you want to follow along: [crayon-6a707eef6ee1e396918874/] I'm purposely setting my Cost Threshold for Parallelism to be low here because I want to demonstrate what happens when…

Read more about User-defined scalar functions suck – even when they don’t access data. 22 comments — Join the discussion

Book Review: Learn T-SQL Querying by Pedro Lopes and Pam Lahoud

You've been writing queries for at least a year or two, and you're curious about what's happening under the hood when SQL Server runs a query. You want to know what you can do to improve your queries, tune your indexes, and change SQL Server's configuration settings so that your results will return faster.

The book Learn T-SQL Querying is for curious people like you.

Read more about Book Review: Learn T-SQL Querying by Pedro Lopes and Pam Lahoud 15 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
T-SQL & Development

What’s New in SQL Server 2019: Faster Functions

A while back, we talked you through a public whitepaper about how Microsoft was working on making user-defined functions go faster. Now that the preview of SQL Server 2019 is out, you can start getting your hands on Froid, the performance-boosting feature. Here's the documentation on it - let's see how it works. Using the…

Read more about What’s New in SQL Server 2019: Faster Functions 10 comments — Join the discussion
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

Hash Join Memory Grant Factors

Buskets
Much like Sorts, Hash Joins require some amount of memory to operate efficiently  -- without spilling, or spilling too much.

And to a similar degree, the number of rows and columns passed to the Hashing operator matter where the memory grant is concerned. This doesn't mean Hashing is bad, but you may need to take some extra steps when tuning queries that use them.

Read more about Hash Join Memory Grant Factors 8 comments — Join the discussion