I have query for example:
SELECT TOP 10
User.id,
User.Name,
Country.Country
FROM User
Inner Join Country
ON Country.Id = User.CountryId
where User.PlanId = 1
In this case SQL manager show in execution plan that use Hash-match and it is pretty fast.
But if I use where User.PlanId = 2 SQL manager use Nested loop for my query and it is very slow... Why with different search criteria it use different algorithmic? How can I fix it?
Country.Idis a primary key or at least unique? hmm.. sometimes workaround can be to useleft join+ add conditionand user.countryid is not null..