You wrote a query. You joined tables.
You have the right ON clause.
You have the right WHERE clause.
But the query plan has a problem!
How Could This Happen To Me?
Oh, relax. You’re not crazy. You just assumed the worst.
Like me whenever I feel pain near my liver.
Call the mortician.
For a query like this, the optimizer can play some tricks.
SELECT TOP 10 p.OwnerUserId, c.Id
FROM dbo.Posts AS p
JOIN dbo.Comments AS c
ON p.OwnerUserId = c.UserId
WHERE p.OwnerUserId = 22656
One of our join columns is in the where clause, too.
That means our plan looks like this!
You see, when the optimizer looks at the join and the where, it knows that if it pushes the predicate to the two index seeks, whatever values come out will match.
I don’t think it even needs the join at that point, but hey.
It certainly doesn’t need the warning.
Thanks for reading!
Brent says: Erik’s like that dying replicant at the end of Blade Runner. He’s seen things you people wouldn’t believe. Also, he has superhuman strength.