What is a Bookmark Lookup in Sql Server?

2019-01-18 19:54发布

I'm in the process of trying to optimize a query that looks up historical data. I'm using the query analyzer to lookup the Execution Plan and have found that the majority of my query cost is on something called a "Bookmark Lookup". I've never seen this node in an execution plan before and don't know what it means.

Is this a good thing or a bad thing in a query?

3条回答
祖国的老花朵
2楼-- · 2019-01-18 20:29

A bookmark lookup is the process of finding the actual data in the SQL table, based on an entry found in a non-clustered index.

When you search for a value in a non-clustered index, and your query needs more fields than are part of the index leaf node (all the index fields, plus any possible INCLUDE columns), then SQL Server needs to go retrieve the actual data page(s) - that's what's called a bookmark lookup.

In some cases, that's really the only way to go - only if your query would require just one more field (not a whole bunch of 'em), it might be a good idea to INCLUDE that field in the non-clustered index. In that case, the leaf-level node of the non-clustered index would contain all fields needed to satisfy your query (a "covering" index), and thus a bookmark lookup wouldn't be necessary anymore.

Marc

查看更多
The star\"
3楼-- · 2019-01-18 20:34

It's a NESTED LOOP which joins a non-clustered index with the table itself on a row pointer.

Happens for the queries like this:

SELECT  col1
FROM    table
WHERE   col2 BETWEEN 1 AND 10

, if you have an index on col2.

The index on col2 contains pointers to the indexed rows.

So, in order to retrieve the value of col1, the engine needs to scan the index on col2 for the key values from 1 to 10, and for each index leaf, refer to the table itself using the pointer contained in the leaf, to find out the value of col1.

This article points out that a Bookmark Lookup is SQL Server 2000's term, which is replaced by NESTED LOOP's between the index and the table in SQL Server 2005 and above

查看更多
孤傲高冷的网名
4楼-- · 2019-01-18 20:35

From MSDN regarding Bookmark Lookups:

The Bookmark Lookup operator uses a bookmark (row ID or clustering key) to look up the corresponding row in the table or clustered index. The Argument column contains the bookmark label used to look up the row in the table or clustered index. The Argument column also contains the name of the table or clustered index in which the row is looked up. If the WITH PREFETCH clause appears in the Argument column, the query processor has determined that it is optimal to use asynchronous prefetching (read-ahead) when looking up bookmarks in the table or clustered index.

查看更多
登录 后发表回答