Query Optimization and Execution Plans

How SQL Server compiles, optimizes, and executes individual queries.

573 associated posts292 primary posts

Performance Tuning

Creating Tables and Stored Procedures in TempDB – Permanently

No, not #tables - actual tables. Here's how: [crayon-6a70bed04ff2b873879076/] The first one disappears when my session is over, but the latter two persist until the SQL Server is restarted. Why would you ever do the latter two? Say you need to share data between sessions, or between different applications, or staging tables for a data…

Read more about Creating Tables and Stored Procedures in TempDB – Permanently 47 comments — Join the discussion

Stats Week: Statistics Terminology Cheatsheet

These things used to confuse me so much
Despite having worked at a Market Research company for a while, I know nothing about statistics, other than that project managers have all sorts of disagreeably subjective phrases for describing them. Vast majority, convincing plurality, dwindling minority, et al. Less talky, more picture.

When I started getting into SQL Server, and learning about statistics, I heard the same phrases over and over again, but wasn't exactly sure what they meant.

Read more about Stats Week: Statistics Terminology Cheatsheet 7 comments — Join the discussion

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

Why most of you should leave Auto-Update Statistics on

Oh God, he's talking about statistics again Yeah, but this should be less annoying than the other times. And much shorter. You see, I hear grousing. Updating statistics was bringin' us down, man. Harshing our mellow. The statistics would just update, man, and it would take like... Forever, man. Man. But no one would actually…

Read more about Why most of you should leave Auto-Update Statistics on 16 comments — Join the discussion
Performance Tuning

Unique Indexes and Row Modifications: Weird

Confession time This started off with me reading a blurb in the release notes about SQL Server 2016 CTP 3.3. The blurb in question is about statistics. They're so cool! Do they get fragmented? NO! Stop trying to defragment them, you little monkey. Autostats improvements in CTP 3.3 Previously, statistics were automatically recalculated when the…

Read more about Unique Indexes and Row Modifications: Weird 3 comments — Join the discussion

Database-Scoped Configurations Replace Trace Flags.

Trace flags are special switches that, when you flip them, enable different behaviors in your SQL Server. Back in the SQL Server 2000-2005 days, these were super-rare undocumented tricks that were handed out by Microsoft support to fix rare cases.

Over time, some trace flags have become so commonplace that they worked their way into some best-practices setup checklists, like:

Read more about Database-Scoped Configurations Replace Trace Flags. 23 comments — Join the discussion
T-SQL & Development

Don’t Use Scalar User-Defined Functions in Computed Columns.

Scalar functions in computed columns cause all queries that hit that table to execute serially. But it gets worse!
Scalar functions in computed columns
cause index maintenance to go single-threaded.
If you're running Expensive Edition, index rebuilds can be both online and parallel. That's pretty cool, because it keeps all your gadgets and gizmos mostly available during the whole operation, and the parallel bit usually makes things faster.

Read more about Don’t Use Scalar User-Defined Functions in Computed Columns. 27 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

Improved diagnostics for query execution plans that involve residual predicate pushdown

I love stuff like this!
Even though it's not on my list of dream features, it's pretty neat. Getting new views into what SQL is doing when queries execute is pretty cool. You can read the short and gory details at the KB here: Improved diagnostics for query execution plans that involve residual predicate pushdown in SQL Server 2012

Read more about Improved diagnostics for query execution plans that involve residual predicate pushdown 6 comments — Join the discussion
Performance Tuning

Filtered Indexes: Just Add Includes

I found a quirky thing recently While playing with filtered indexes, I noticed something odd. By 'playing with' I mean 'calling them horrible names' and 'admiring the way other platforms implemented them'. I sort of wrote about a similar topic in discussing indexing for windowing functions. It turns out that a recent annoyance could also…

Read more about Filtered Indexes: Just Add Includes 30 comments — Join the discussion