码迷,mamicode.com
首页 > 其他好文 > 详细

Index Key Column VS Index Included Column

时间:2021-06-02 14:39:23      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:overflow   explain   operator   rom   hyper   keyword   not   from   currently   

Index Key Column VS Index Included Column

Can someone explain this two - Index Key Column VS Index Included Column?

Currently, I have an index that has 4 Index Key Column and 0 Included Column.

Thanks

 

回答1

Index key columns are part of the b-tree of the index. Included columns are not.

Take two indexes:

CREATE INDEX index1 ON table1 (col1, col2, col3)
CREATE INDEX index2 ON table1 (col1) INCLUDE (col2, col3)

index1 is better suited for this kind of query:

SELECT * FROM table1 WHERE col1 = x AND col2 = y AND col3 = z

Whereas index2 is better suited for this kind of query:

SELECT col2, col3 FROM table1 WHERE col1 = x

In the first query, index1 provides a mechanism for quickly identifying the rows of interest. The query will (probably) execute as an index seek, followed by a bookmark lookup to retrieve the full row(s).

In the second query, index2 acts as a covering index. SQL Server doesn‘t have to hit the base table at all, since the index provides all the data it needs to satisfy the query. index1 could also act as a covering index in this case.

If you want a covering index, but don‘t want to add all columns to the b-tree because you don‘t seek on them, or can‘t because they aren‘t an allowed datatype (eg, XML), use the INCLUDE clause.

 

Index Key Column VS Index Included Column

标签:overflow   explain   operator   rom   hyper   keyword   not   from   currently   

原文地址:https://www.cnblogs.com/chucklu/p/14823135.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!