To start with, a small stored procedure that I use all the time for bad parameter sniffing demos that reliably gets different plans with different values due to statistics skew:
123456789101112CREATEPROC dbo.spAddressByCity @City NVARCHAR(30)ASSELECTa.AddressID,a.AddressLine1,a.AddressLine2,a.City,sp.NameASStateProvinceName,a.PostalCodeFROMPerson.AddressASaJOINPerson.StateProvinceASspONa.StateProvinceID = sp.StateProvinceIDWHEREa.City = @City;If this procedure is called for a value of ‘London’ it gets a plan with a Merge Join. For most other value it gets a plan with a Loops Join. Here’s an example of the ‘London’ plan:
It’s a good question with a good answer.