I'm looking into optimizing some queries in SQL Server 2016, and I ran into this situation which I couldn't understand.
This particular query is trying to get the name of two sets of Objects in the dbo.Objects table. To do this, the Query Plan shows SQL is using a Key Lookup in a Nested Loop Inner Join after retrieving the clustered indexes. However, doing the Key Lookup for the larger set of Objects has an estimated cost that is less than the Key Lookup for the smaller set of Objects. They're both operating on the same table, using the same clusterd index for the lookup, the same predicates, so I don't see what else could affect their cost estimates besides the row numbers, but that seems to have the opposite result.
The only differences I could find in the properties were the estimated/actual executions, and the estimated rebinds/rewinds. The smaller set had estimated 5854 rebinds and no rewinds, while the larger set estimated 1069.66 rebinds and 22356.9 rewinds. However, I don't know what those mean in the context of Key Lookups
Here are the tooltips for each operation to show what I'm talking about.
Why might these operators have such different Estimated Operator Counts?