Improving Cardinality Estimation: Answers & Discussion


Your challenge for last week was to take this Stack Overflow database query to show the top-ranking users in the most popular location:

CREATE INDEX Location ON dbo.Users(Location); GO CREATE OR ALTER PROC dbo.GetTopUsersInTopLocation AS SELECT TOP 200 u.Reputation, u.Id, u.DisplayName, u.WebsiteUrl, u.CreationDate FROM dbo.Users u WHERE u.Location = (SELECT TOP 1 Location FROM dbo.Users WHERE Location <> N » GROUP BY Location ORDER BY COUNT(*) DESC) ORDER BY u.Reputation DESC; GO

And make it read less pages only by tuning the query? You weren’t allowed to make index or server changes, and you weren’t allowed to hard code the location in