I have a very simple select on SQL Server:
select * from person
where first_name = 'John' and last_name = 'Smith'`
In the execution plan I have:
- Nonclustered Index seek – NC_First_Last_pers
- Key lookup (Clustered) on PK
And this two goes into a Nested Loop Join.
My question is:
Why is there the join? I thought that this is used only for joining different tables, but I have only 1 table here.
Thanks!
In the index you have the data for the columns that are included in the index plus the clustered key. You are querying the table with
*meaning that you have to go look for all column values and those are stored together with the clustered key.The query uses the index on the names to find all rows that match and then uses the clustered key to find the data you want.