Performance Tuning

Query Exercise Answers: Solving the 201 Buckets Problem

In this week's Query Exercise challenge, I explained SQL Server's 201 buckets problem. SQL Server's statistics only handle up to ~201 outliers, which means that outliers ~202-300 get wildly inaccurate estimates.

In our example, I had an index on Location and perfectly accurate statistics, but even still, this query gets bad estimates because Lithuania is in outliers ~202-300:

Read more about Query Exercise Answers: Solving the 201 Buckets Problem 8 comments — Join the discussion

About Half Of You Don’t Have Your Databases Under Control.

I ran a poll over on LinkedIn to find out if people have 100% of their databases under some kind of source control or version control.

I broke the answers up into two sets, developers and non-developers, because I had a hunch that the developers' answers would be very different than the rest, and indeed they were:

Read more about About Half Of You Don’t Have Your Databases Under Control. 10 comments — Join the discussion
Performance Tuning

Query Exercise: Solving The 201 Buckets Problem

When you run a query, SQL Server needs to estimate the number of matching rows it'll find - so that it can decide which indexes to use, whether to go parallel, how much memory to grant, and more.

For example, take any Stack Overflow database, and let's say I have an index on Location, and I want to find the top-ranking users in Lithuania:

Read more about Query Exercise: Solving The 201 Buckets Problem 14 comments — Join the discussion
Performance Tuning

Query Exercise Answer: What Makes SELECT TOP 1 or SELECT MAX Different?

This Query Exercise was very different: I didn't ask you to solve a particular problem. I pointed out that I've heard advice that SELECT MAX is faster than SELECT TOP 1, and that's not quite true. I asked you to find factors that would cause these two queries to get different execution plans: [crayon-6a79dc0fba894591492077/] In the…

Read more about Query Exercise Answer: What Makes SELECT TOP 1 or SELECT MAX Different? 4 comments — Join the discussion

SQL ConstantCare® Population Report: Summer 2024 (And Upcoming Gamification Badges)

The short story: SQL Server 2022 finally saw some growth this quarter! Two years after the release, 1 in 10 SQL Servers is finally running the latest version.

The long story: ever wonder how fast people are adopting new versions of SQL Server, or what’s “normal” out there for SQL Server adoption rates? Let’s find out in the summer 2024 version of our SQL ConstantCare® population report.

Read more about SQL ConstantCare® Population Report: Summer 2024 (And Upcoming Gamification Badges) 13 comments — Join the discussion

[Video] I Must Be an Idiot: Automatic Tuning Never Works for Me.

I don't get it. I've given this feature one chance after another, and every time, it takes a smoke break rather than showing up for work.

The latest instance involved the recent Query Exercise where you were challenged to fix a computed column's performance. In the comments, some folks noted that performance of the query was actually great on old compat levels, like SQL Server 2008, and that it only sucked on newer compat levels like 2016 and later.

Read more about [Video] I Must Be an Idiot: Automatic Tuning Never Works for Me. 21 comments — Join the discussion

Thoughts About Stack Overflow’s Annual Developer Survey

Every year, Stack Overflow runs a developer survey about technology, work, community, and more. This year's results include 65,437 responses from developers around the world. The results are biased towards the kinds of developers who use Stack Overflow - 76% of the respondents reported that they have a Stack Overflow account. I would guess that…

Read more about Thoughts About Stack Overflow’s Annual Developer Survey 7 comments — Join the discussion
Performance Tuning

Query Exercise Answer: Fixing a Slow Computed Column

In last week's Query Exercise, we added a user-defined function to the Users table to check whether their WebsiteUrl was valid or not. I noted that even with an index on Reputation, SQL Server 2022 simply ignored the index, did a table scan, and spent 2 minutes of time calling the user-defined function on a row-by-row basis.

Read more about Query Exercise Answer: Fixing a Slow Computed Column 5 comments — Join the discussion
Production DBA

Today’s a Good Day to Talk to Your Manager About Disaster Recovery.

Last night, two major IT disasters struck:

Microsoft Azure's Central region went down for about 4 hours. The official post-mortem isn't out yet, but rumor has it that while decommissioning legacy storage services, the product group deleted the wrong thing.
Crowdstrike pushed a bad update, leading to blue screens of death on Windows systems worldwide, affecting banking, healthcare, airlines, and more.

Read more about Today’s a Good Day to Talk to Your Manager About Disaster Recovery. 10 comments — Join the discussion

Updated, Larger Stack Overflow Demo Database

Stack Overflow publishes a data dump with all user-contributed content, and it's a fun set of data to use for demos. I took the 2024-April data dump, and imported it into a Microsoft SQL Server database.

It's an 31GB torrent (magnet) that expands to a ~202GB database. I used Microsoft SQL Server 2016, so you can attach this to anything 2016 or newer. If that's too big, no worries - for smaller versions and past versions, check out my How to Download the Stack Overflow Database page.

Read more about Updated, Larger Stack Overflow Demo Database 9 comments — Join the discussion