« SELECT COUNT(*) FROM... without a table scan | Main
Sunday
Aug292010

Get rid of Key Lookups

If you see  "Key Lookup" in your execution plan you can build a covering index to speed things up.  Doing a Key Lookup is less optimal than an Index Seek, so when you see these in your execution plans know that you have the option of making this particular operation faster.  Albeit with the chance of adding overhead to the maintenance of your existing index.

Generate your execution plan and hone in on the Key Lookup operations like the one below:

Look at your Nested Loops operation and identifity the columns it's looking for.  An easy way to do this is to right-click on the operation when viewing your execution plan then navigating to Properties - or mashing F4 when it's selected.

Now go to Object Explorer and script out the existing index.  Under Included columns add all columns that are contained in the Nested Loop operation that aren't already in the existing index.

An included column is adding a non-key column to the leaf level of the index.  There will be a slight overhead to your index upkeep, but if this is an often-executed operation it might be well worth it!

References (1)

References allow you to track sources for this article, as well as articles that were written in response to this article.
  • Response
    [...]Get rid of Key Lookups - SQL - Query Tuning - RyanBoyer.net[...]

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>