Query Optimization and Execution Plans

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

573 associated posts292 primary posts

Production DBA

Office Hours: One-Word Answers Edition

Some of the questions y'all post at https://pollgab.com/room/brento are pretty straightforward. Let's get 'er done. LetTheDbaHandleIt: My friend needs to track who has accessed what data. This is easy at OS and app level, but how can my friend verify that those who have direct DB access are not snooping on data inappropriately? e.g. payroll or…

Read more about Office Hours: One-Word Answers Edition 5 comments — Join the discussion
Performance Tuning

PSPO: How SQL Server 2022 Tries to Fix Parameter Sniffing

Parameter sniffing is a notorious problem for Microsoft SQL Server because it tries to reuse execution plans, which doesn't work out well for widely varying parameters. Here's a primer for the basics about how it happens. SQL Server 2022 introduces a new feature called Parameter Sensitive Plan optimization. I'm not really sure why Microsoft capitalized…

Read more about PSPO: How SQL Server 2022 Tries to Fix Parameter Sniffing 38 comments — Join the discussion
Production DBA

Office Hours Speed Round, Text Edition

Got questions for me? Post 'em at https://pollgab.com/room/brento and upvote the ones you'd like to see me cover. I filter out the ones that are too short for video answers, and here's the latest batch:

Corrupted: Should DBCC CheckDB be run on secondary replicas in AG as well ? Is it recommended to attach corrupted database to Prod server, to check how your integrity check job will react ?

Read more about Office Hours Speed Round, Text Edition 20 comments — Join the discussion
Performance Tuning

Estimated and Actual Plans Can Have Different Shapes.

A reader posted a question for Office Hours: Hi Brent, What is your take on Hugo Kornelis's explanation of execution plan naming. As her his explanation, estimated exec plan is simply an execution plan whereas actual execution plan = execution plan+run-time stats. Do you agree that the naming is flawed and confusing? - Yourbiggestfan I…

Read more about Estimated and Actual Plans Can Have Different Shapes. 17 comments — Join the discussion
Production DBA

Office Hours Speed Round: Text Edition

Not all of the questions you post at https://pollgab.com/room/brento are hard. Some of 'em can be answered in one line:

Q: accidentalDBA: Hi Brent, My friend is moving from two physical servers (production + failover) to VMs on the same host and SAN. His manager wants to keep log shipping as a DR solution. I advised against this as most disasters would affect both VMs equally. Am I missing something?

Read more about Office Hours Speed Round: Text Edition 10 comments — Join the discussion
Performance Tuning

SQL Server 2022 Tells You Why A Query Can’t Go Parallel.

Until 2022, when a query couldn't go parallel, all we got was a really cryptic note in the execution plan properties saying NonParallelPlanReason = CouldNotGenerateValidParallelPlan.

But starting with SQL Server 2022, even when I'm running under older compatibility levels:
[crayon-6a738da757bdc508061431/]
The execution plan gives me way more details:

Read more about SQL Server 2022 Tells You Why A Query Can’t Go Parallel. 10 comments — Join the discussion