Launch week: the Season Pass & Fundamentals Week are 50% off — ends in 20d 15h 46mSee the sale

Author: Brent Ozar

I make Microsoft SQL Server go faster. I love teaching, travel, cars, and laughing. I'm based out of Las Vegas. He/him.
Career & Community

Free Live Webcasts: Slide & Demo Versions of How to Think Like the Engine

You’re comfortable writing queries to get the data you need.

But you're uncomfortable if someone asks you how it works, how SQL Server and Azure SQL DB turn your queries into results. You know there are execution plans, but ... you're uncomfortable reading them. You know queries need indexes, but you're not sure which columns to put in order, or how SQL Server chooses between them.

Read more about Free Live Webcasts: Slide & Demo Versions of How to Think Like the Engine 6 comments — Join the discussion
T-SQL & Development

Option Recompile is a Magic Turbo Button That Actually Works.

I didn't say that - Guy Glantser did.

Guy Glantser is an Israeli SQL Server guru with a ton of great presentations on YouTube. I've had the privilege of hanging out with him in person a bunch of times over the year, and I'll always get excited to do it again. He's not just smart, but he's friendly and funny as hell.

Read more about Option Recompile is a Magic Turbo Button That Actually Works. 29 comments — Join the discussion
Performance Tuning

What Happens When Multiple Queries Compile at Once?

An interesting question came in on PollGab. DBAmusing asked: If a query takes 5-7s to calculate the execution plan (then executes <500ms) if multiple SPIDS all submit that query (different param values) when there's no plan at start, does each SPID calc the execution plan, one after the other after waiting for the prior SPID…

Read more about What Happens When Multiple Queries Compile at Once? 5 comments — Join the discussion
Performance Tuning

Finding Sister Locations to Help Each Other: Answers & Discussion

This week's query exercise asked you to find two kinds of locations in the Stack Overflow database:

Locations populated with users who seem to be really helpful, meaning, they write really good answers
Locations where people seem to need the most help, meaning, they ask a lot of questions, but they do not seem to be answering those of their neighbors

Read more about Finding Sister Locations to Help Each Other: Answers & Discussion 2 comments — Join the discussion
Performance Tuning

Query Exercise: Finding Sister Locations to Help Each Other

For this week's query exercise, let's start with a brief query to get a quick preview of what we're dealing with:
[crayon-6a364b6247c12187432448/]

That query has a few problems, but hold that thought for a moment. (You're going to have to solve those problems, but I just wanted to show you the sample data at first to give you a rough idea of what we're dealing with.)

Read more about Query Exercise: Finding Sister Locations to Help Each Other 12 comments — Join the discussion
Performance Tuning

Find Recent Superstars: Answers & Discussion

Your query exercise for this week was to write a query to find users created in the last 90 days, with a reputation higher than 50 points, from highest reputation to lowest. Because everyone's Stack Overflow database might be slightly different, we had to start by finding the "end date" for our query. I'm working with the 2018-06 export that I use in my training classes, so here's my end date:

Read more about Find Recent Superstars: Answers & Discussion 1 comment — Join the discussion
Career & Community

Join Me in Orange County for Tuning Databases in One Day

You've got production databases in SQL Server or Azure SQL DB, and you want to make 'em faster. You need to identify the database's bottleneck, prove the root cause, and then recommend fixes. You want to make the right choice for each bottleneck - should you do index changes, query tuning, or server-level settings? The…

Read more about Join Me in Orange County for Tuning Databases in One Day Be the first to comment

Sessions You Should Attend at SQLBits Online 2024

SQLBits 2024 is next month, and the session agenda is out, including the Microsoft-led sessions.

If you're going to get the boss to buy you an online or in-person ticket, it'll help if you have a specific list of sessions you wanna attend. Managers love it when you can point at each session and say, "Here's why this is going to be useful to the business."

Read more about Sessions You Should Attend at SQLBits Online 2024 1 comment — Join the discussion
Performance Tuning

Query Exercise: Finding Long Values Faster

Our developers have come to us with a problem query that isn't as fast as they'd like. Using any Stack Overflow database:
[crayon-6a364b624b9a2448287891/]
It has an index, but SQL Server refuses to use that index in the execution plan:

If we force the index with a query hint, we do indeed get dramatically lower logical reads. In my particular database's case, the clustered index scan is 141,573 logical reads - but scanning the DisplayName index alone is just 38,641 logical reads.

Read more about Query Exercise: Finding Long Values Faster 45 comments — Join the discussion
Performance Tuning

Improving Cardinality Estimation: Answers & Discussion

Your challenge for last week was to take this Stack Overflow database query to show the top-ranking users in the most popular location:
[crayon-6a364b624c1eb145697196/]
And make it read less pages only by tuning the query? You weren't allowed to make index or server changes, and you weren't allowed to hard code the location in the query since it might change over time.
The Core of the Problem
The main problem is that when we run a statement (like SELECT), SQL Server:

Read more about Improving Cardinality Estimation: Answers & Discussion 16 comments — Join the discussion
T-SQL & Development

The Last Ticket/Issue I Closed #TSQL2sday

For this month's T-SQL Tuesday, I asked y'all to write about the most recent ticket or issue that you closed. (If you want to see other peoples' posts, you can check out the comments on that invite post, or wait til next week and I'll publish a wrap-up of everyone's answers.)

A past client emailed me with a performance emergency. Things had been going just fine, and then out of nowhere, things suddenly slowed down.

Read more about The Last Ticket/Issue I Closed #TSQL2sday 19 comments — Join the discussion