When a query filters a large table on a range, like a date window, and no index supports that range, SQL Server scans the table. Put that scan inside a subquery that gets joined to other inputs, and a query that should take seconds can run for hours. In a recent case, one covering index took a query from almost two hours in the worst case down to about four seconds. What is an unindexed range predicate? A range predicate …

SQL Code Smells: Unindexed Range Predicates Read more →