4.2 Tuning usp_SearchPostsByPostType

In usp_SearchPostsByPostType, people can query for PostTypeIds that have dramatically different numbers of rows in the Posts table. What makes matters even worse is that they’re passing in the name of the PostType, not the ID, so SQL Server doesn’t stand a chance of cardinality estimation.

In usp_SearchPostsByPostType, people can query for PostTypeIds that have dramatically different numbers of rows in the Posts table. What makes matters even worse is that they’re passing in the name of the PostType, not the ID, so SQL Server doesn’t stand a chance of cardinality estimation.