[Video] Office Hours: Waiting for the Hot Tub to Fill
While waiting for my Husavik hot tub to fill up, I took your top-voted questions from https://pollgab.com/room/brento.
https://www.youtube.com/watch?v=f0chyzVLFYw
How SQL Server compiles, optimizes, and executes individual queries.
573 associated posts292 primary posts
While waiting for my Husavik hot tub to fill up, I took your top-voted questions from https://pollgab.com/room/brento.
https://www.youtube.com/watch?v=f0chyzVLFYw
Regular expressions are a way of doing complex string searches. They can be really useful, but they have a reputation: they're hard to write, hard to read, and they're even harder to troubleshoot. Once you master 'em, though, they come in handy for very specific situations.
This post isn't about their complexity, though. This post is about Azure SQL DB & SQL Server 2025's regex performance.
Meet my latest toy, a 1991 Honda Beat! I introduce it, then take your top-voted questions from https://pollgab.com/room/brento.
https://www.youtube.com/watch?v=gkeEKyzc01M
I took your top-voted questions from https://pollgab.com/room/brento and answered 'em from my balcony at Disney's Aulani Resort in Hawaii. I'm not really a Disney guy - we were there for a friend's birthday celebration - but I tell ya what, that's my new favorite resort in the world. The water park, food, beach, and nearby activities were great, and it has the awesome Disney service. Top notch. Anyhoo, back to tech:
Most of the time, I love Entity Framework, and ORMs in general. These tools make it easier for companies to ship applications. Are the apps perfect? Of course not - but they're good enough to get to market, bring in revenue to pay salaries, and move a company forwards.
However, just like any tool, if you don't know how to use it, you're gonna get hurt.
For the last Office Hours of the year, I'm coming to you from Tokyo, the last stop on my 3-week tour of China and Japan. This was a big Epic Life Quest task for me, for sure, something I've wanted to do for decades. Let's bring you along and go through your top-voted questions from https://pollgab.com/room/brento:
What, doesn't everyone park a convertible in their dining room? I address the pink elephant in the room, and then take your top-voted questions from https://pollgab.com/room/brento.
https://www.youtube.com/watch?v=9utvLk9K9Qc
Let's start with the Stack Overflow database (any size will work), drop all the indexes on the Users table, and run a delete:
[crayon-6a71e91ba3114032533740/]
Let's say we have a couple of update statements we need to run every 15 minutes in the Stack Overflow database, and we've built indexes to support them:
[crayon-6a71e91ba3417398594678/]
About 10 years ago, Microsoft made changes to the Cardinality Estimator (CE) which caused some problems for SQL Server upgrades. When folks upgraded to SQL Server 2014, they also casually switched their databases' compatibility level to the latest version, because for years that hadn't really affected query plans. They just figured they wanted the "latest and greatest" compat level, without regard to the effects. That backfired badly when they suddenly got 2014's Cardinality Estimation changes.
This week's Query Exercise challenged you to figure out why these 3 estimates went so badly:
[crayon-6a71e91ba4062399748653/]
I went live on TikTok and took your top-voted questions from https://pollgab.com/room/brento:
https://www.youtube.com/watch?v=R98zeXqpBRQ
Our prior Query Exercise introduced SQL Server's 201 buckets problem: its inability to accurately estimate rows for more than 201 outliers in a table. I followed up with a solution using filtered statistics to help with the next 200 outliers, and I talked about how that's really overkill for the simple problem we were facing in that initial challenge.
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:
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:
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-6a71e91ba5246126827616/] In the…
These two queries both get the same answer from the Stack Overflow database:
[crayon-6a71e91ba5b1a122003542/]
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.
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.
Take any size of the Stack Overflow database and check out the WebsiteUrl column of the Users table:
Sometimes it's null, sometimes it's an empty string, sometimes it's populated but the URL isn't valid.