简体   繁体   中英

SQL Server Query execution plan

I am trying to learn about optimizing databases and queries. I have a test table Objednavka , that has a foreign key attribute ODIS . In this database, queries like

SELECT * FROM Objednavka WHERE ODIS = 123

are frequent, so I created an index like this

CREATE NONCLUSTERED INDEX Objednavka_ODIS_index ON Objednavka (ODIS)

I then looked at the plan of the query I mentioned and this is what I see:

查询计划

Can someone please explain why do I have the Index Seek and Key Lookup operations performed in parallel, then joined using Nested Loops? From what I learned, I thought that the Index Seek should be performed first , so that the engine finds the location of the row that contains (the indexed) ODIS attribute in the index, and then it should retrieve the whole data using Key Lookup , when it already knows the location, or am I wrong?

non clustered index has the PK columns added to it automatically by SQL Server. The index seek is to seek the index b-tree for the value(s) you provided for the indexed column(s) and the result is the PK values (or RIDs if your table is a heap). If all the columns you queried are part of the indexed columns, which is called a covering index, you query is done because SQL server can get all the information from the b-tree. If you need to return other columns not in the index, SQL server needs to find the data of the record using the PK, which is the key-lookup part.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM