Execution Strategies and Runtime Behavior

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

93 associated posts89 primary posts

Another Hidden Parallelism Killer: Scalar UDFs In Check Constraints

Every single time
Really. Every single time. It started off kind of funny. Scalar functions in queries: no parallelism. Scalar functions in computed columns: no parallelism, even if you're not selecting the computed column. Every time I think of a place where someone could stick a scalar function into some SQL, it ends up killing parallelism. Now it's just sad.

Read more about Another Hidden Parallelism Killer: Scalar UDFs In Check Constraints 15 comments — Join the discussion

Still Serial After All These Years

With each new version of SQL comes a slew of new stuff
While some changes are cosmetic, others bewildering, and the rest falling somewhere between "who cares about JSON?" and "OH MY GOD TAKE MY MONEY!", but not really my money, because I only buy developer edition. Aaron Bertrand has done a better job finding, and teaching you how to find new features than I could. Head over to his blog if you want to dive in.

Read more about Still Serial After All These Years 30 comments — Join the discussion
Performance Tuning

When does a Query Get Trivial Optimization?

We had some great questions about trivial execution plans in SQL Server in our Advanced Querying and Indexing class a few weeks ago. Here's a little glimpse into what we talked about.

For really simple queries, SQL Server can use "trivial optimization". If there's a very limited number of ways to run the query, why do a bunch of fancy, CPU burning cost-based optimization? Just chuck the plan at the query and let it go!

Read more about When does a Query Get Trivial Optimization? 6 comments — Join the discussion
Performance Tuning

How many CPUs is my parallel query using in SQL Server?

Parallelism can be confusing. A single query can have multiple operators that run at the same time. Each of these operators may decide to use multiple threads. You set SQL Server's "max degree of parallelism" to control the number of processors that can be used, but it's not immediately obvious what this means. Does this setting…

Read more about How many CPUs is my parallel query using in SQL Server? 4 comments — Join the discussion

SQL Server’s Cost Threshold for Parallelism

"Should a query get to use more than one CPU core?" That's an important question for your SQL Server. If you're not sure what parallelism is, get started by exploring the mysteries of CXPACKET with Brent. He'll introduce you to the the setting, 'Cost Threshold for Parallelism'.
Let's test Cost Threshold for Parallelism
I generate an estimated execution plan for the following query. I'm running against a copy of the StackOverflow database that doesn't have many indexes.

Read more about SQL Server’s Cost Threshold for Parallelism 20 comments — Join the discussion
Performance Tuning

Are SQL Server Functions Dragging Your Query Down?

In most coding languages, functions are often-used blocks of code that can be reused from multiple locations, leading to less code – and cleaner code. SQL Server also lets us create functions that can be used the same way. They are reusable blocks of code that can be called from multiple locations. So, if you need to format phone numbers a certain way, or parse for specific characters, you can do so using a function.

Read more about Are SQL Server Functions Dragging Your Query Down? 20 comments — Join the discussion

Q: Can High MaxDOP make a query SLOWER?

Answer: Yep, sometimes it can.I used to think that higher degrees of parallelism followed a law of diminishing returns-- you could add more threads, but the benefits would taper off. But it's a bit more complicated than that. Microsoft's recommendation to be careful when setting maxdop to values over 8 is a warning worth heeding.Lowering maxdop…

Read more about Q: Can High MaxDOP make a query SLOWER? 15 comments — Join the discussion

Recommended Books for SQL Server DBAs and Developers

Here's my favorite SQL Server books for 2016-2014:

T-SQL Fundamentals - (updated for SQL 2016) - don't be fooled by this "fundamentals" title, because everybody who writes T-SQL queries needs this book. It's the manual we should have been given when we started, and everyone's going to learn something about concurrency, performance, and updates here.

Read more about Recommended Books for SQL Server DBAs and Developers 93 comments — Join the discussion