The Query Tuning Trick You Should Use More: Pagination


When I’m tuning queries, the normal answer is to make the query perform better – either via changing the T-SQL, adding hints, or adding indexes so that the data’s better prepared for the query.

However, sometimes when I’m looking at the output of sp_BlitzCache, I scroll across to the Average Rows column and double-check that the query’s actually returning a reasonable number of rows out in the wild.

I’ve uncovered some amusing situations, like a back end process that was supposedly fetching the emails that were ready to be sent out. We noticed that it was one of the top