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. The Stack Overflow database even has an index to support it:

But the query takes several seconds to run, and the query plan has tons of estimation problems:

That’s where you come in, dear reader: can you make this query use less resources and run faster only by tuning the query?

I know, you love tuning indexes or changing server settings, but as you love to tell your developers, you can’t always throw indexes or go pulling on knobs every time there’s a query-level problem. You can make ANY changes you want to the stored procedure that you would actually implement in real life, but that’s it.

Post your solutions in the comments, and feel free to ask other folks questions about their solutions. Have fun! We’ll revisit your solutions in this post about the answers.

Previous Post
Finding Tagged Questions Faster: Answers & Discussion
Next Post
Improving Cardinality Estimation: Answers & Discussion

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed