Key Lookups and the Tipping Point
A nonclustered index that helps at a hundred rows can hurt at a hundred thousand. The reason is what happens after the index finds each row.
3 min readSQL Server 2022

A nonclustered index stores its key columns and a pointer to the rest of the row. When a query needs columns the index does not hold, the engine follows that pointer and reads the row from the clustered index. That operation appears in the plan as a Key Lookup, and it runs once per matching row.
Why does a Key Lookup get expensive as rows grow?
An index seek that matches ten rows performs ten lookups. Each is a small B-tree descent into the clustered index, landing on an arbitrary page. Ten random page accesses is nothing.
The same seek matching two hundred thousand rows performs two hundred thousand descents. Now compare that against the alternative: scanning the clustered index reads every page once, in physical order, and the operating system and storage layer both handle that well.
There is a crossover. Below it the index wins by a large margin; above it the scan wins by a large margin. The optimizer estimates the row count and picks a side, and when the estimate is right it picks correctly.
That is the important framing. A plan that abandons your index is usually not the optimizer being wrong. It is the optimizer telling you the index does not cover the query.
Reading it in the plan
|--Nested Loops (Inner Join) |--Index Seek (NonClustered) [orders].[IX_orders_status] |--Key Lookup (Clustered) [orders].[PK_orders]The Key Lookup under a Nested Loops join is the shape. The number of executions on the lookup operator is the number of rows the seek produced — that is the count that matters, not the number of rows returned to the client, which may be far smaller if a filter is applied above.
The other detail worth reading is the output list on the Key Lookup. It names the
columns the index was missing, which is precisely the list of candidates for
INCLUDE.
How is a Key Lookup removed?
Adding those columns as included columns rather than key columns removes the lookup: the index now answers the query on its own, and the plan becomes a single seek.
CREATE NONCLUSTERED INDEX IX_orders_status ON dbo.orders (status) INCLUDE (customer_id, total_amount, created_at) WITH (DROP_EXISTING = ON);The cost is real: the index is wider, so it holds fewer rows per page, occupies more memory, and every update to any included column now writes to this index as well. Covering a query returning three columns is usually a good trade. Covering one that returns fifteen is building a second copy of the table.
When the list is long, the better question is whether the query needs all of them. An ORM selecting every column by default is the most common reason a Key Lookup cannot be eliminated cheaply.
What not to do
Forcing the index with a hint when the optimizer chose a scan takes the plan that was correctly rejected. If the estimate is right, the hint makes the query slower by design.
If the estimate is wrong — the seek expected two hundred rows and produced two
hundred thousand — that is a statistics problem, and the hint hides it rather than
fixing it. Estimated and Actual Number of Rows on the operator are what to check
first, before either the index or the hint; PostgreSQL reports
the same comparison in EXPLAIN ANALYZE.
Elsewhere
The same mechanism appears under different names. On a heap table SQL Server calls it a RID Lookup. InnoDB performs a second traversal through the clustered index for the same reason, without naming the operator. PostgreSQL’s equivalent is the heap fetch in an index scan, and its bitmap heap scan exists specifically to convert many random fetches into one ordered pass — a middle option the other two lack.
Frequently asked questions
- What is a Key Lookup in a SQL Server execution plan?
- A nonclustered index stores its key columns and a pointer to the rest of the row. When a query needs columns the index does not hold, the engine follows that pointer and reads the row from the clustered index. That operation appears in the plan as a Key Lookup, under a Nested Loops join, and it runs once per matching row. On a heap table the same operation is called a RID Lookup.
- Why did SQL Server stop using my nonclustered index?
- Each Key Lookup is a small descent into the clustered index landing on an arbitrary page, so the total cost grows with the number of matching rows, while scanning the clustered index reads every page once in physical order. There is a crossover point, and past it the scan wins by a large margin. A plan that abandons the index is usually the optimizer reporting that the index does not cover the query.
- How do I get rid of a Key Lookup in SQL Server?
- Read the output list on the Key Lookup operator: it names the columns the index was missing, which is exactly the list of candidates for INCLUDE. Adding them as included columns lets the index answer the query alone and the plan becomes a single seek. The index gets wider in exchange, so it holds fewer rows per page and every update to an included column now writes to it as well.
- Should I use an index hint when SQL Server chooses a scan?
- Forcing the index takes the plan the optimizer correctly rejected, so if the row estimate was right the hint makes the query slower by design. If the estimate was wrong — the seek expected two hundred rows and produced two hundred thousand — that is a statistics problem, and the hint hides it rather than fixing it. Check the estimate before touching either the index or the hint.
References
- docsSQL Server documentation — Showplan logical and physical operators reference (opens in a new tab)
Defines the Key Lookup and RID Lookup operators discussed here.
-- written by
Elias RoweDatabase engineer
Elias Rowe writes about database engineering, SQL performance, and production systems. He focuses on measurable behavior, practical trade-offs, and conclusions that can be reproduced rather than assumed.


