Indexing and Statistics

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

568 associated posts270 primary posts

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
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-6a6f233b9f171824536839/]
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

Query Exercise: Improving Cardinality Estimation

Your challenge for this week is to tune a query. Say Stack Overflow has a dashboard that shows the top-ranking users in their most popular location. It's even got an index to support it:
[crayon-6a6f233b9f87e720132579/]
You can test it with any version of the Stack Overflow database. To test it, we'll turn on a couple of tuning options:
[crayon-6a6f233b9f883851855279/]
The actual execution plan does use our index - not just once, but twice:

Read more about Query Exercise: Improving Cardinality Estimation 33 comments — Join the discussion
Performance Tuning

Database Changes to Find Tagged Questions Faster: Answers and Discussion

In the last Query Exercise discussion, we hit a performance wall when we were trying to quickly find questions with a specific tag. We threw up our hands and said it's time to make database changes, but we had a few restrictions: We have a lot of existing code that uses the Posts.Tags column That…

Read more about Database Changes to Find Tagged Questions Faster: Answers and Discussion 5 comments — Join the discussion
Performance Tuning

Finding Tagged Questions Faster: Answers & Discussion

Your query exercise was to take this Stack Overflow query to find the top-voted questions for any given tag:
[crayon-6a6f233ba0253888848489/]
That's currently using this index in its execution plan:
[crayon-6a6f233ba0258953609294/]
And answer 3 questions:

What kinds of tags will perform worse than others for this query?
Could you change the query to perform better?
Could you change the indexes to perform better, without changing the table structure?

Read more about Finding Tagged Questions Faster: Answers & Discussion 11 comments — Join the discussion