Statistics Aren’t Guarantees: SQL Server Still Checks.

When I’m reviewing plans with folks, I get this response a lot:

But SQL Server should know there’s no data that matches! It has statistics!

Statistics are guideposts, not guarantees.

We’ll start with the Stack Overflow database and put an index on LastAccessDate, which also creates a statistic on that column. We’ll check the min and max LastAccessDates:

CREATE INDEX LastAccessDate ON dbo.Users(LastAccessDate); SELECT MIN(LastAccessDate), MAX(LastAccessDate) FROM dbo.Users;

In the database I’m using today, the min is ‘2008-08-01 00:59:11.147’ and the max is ‘2018-06-03 05:18:24.843’. If I query for all users lower than the min, or all users above the