Indexing and Statistics

Designing, evaluating, maintaining, and troubleshooting indexes and statistics.

568 associated posts270 primary posts

Performance Tuning

Query Exercise: Why Are These 3 Estimates So Wrong?

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.

Read more about Query Exercise: Why Are These 3 Estimates So Wrong? 6 comments — Join the discussion
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
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-6a6f0c290808e203360714/] In the…

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

Does Bit Column Order Matter in Tables?

At the PGConf.dev, where Postgres developers get together and strategize the work they wanna do for the next version, I attended a session where Matthias van de Meent talked about changing the way Postgres stores columns. As of right now (Postgres 17), columns are aligned in 8-bit intervals, so if you create a table with alternating columns:

Read more about Does Bit Column Order Matter in Tables? 3 comments — Join the discussion

[Video] Office Hours: Ask Me Anything About Azure and Microsoft Databases

Back at home in the office, time to settle in with a nice caffeine-free Diet Coke and go through your top-voted questions from https://pollgab.com/room/brento. Why caffeine-free? Because I slug multiple coffees first thing in the morning when I wake up (usually around 3am-4am), and by the time I stream with y'all, I don't need any more go juice.

Read more about [Video] Office Hours: Ask Me Anything About Azure and Microsoft Databases 4 comments — Join the discussion