zoukankan      html  css  js  c++  java
  • Index Key Column VS Index Included Column

    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.

  • 相关阅读:
    如何删除一个CSDN上自己上传的资源
    ubuntu 安装 boost
    C#-提取网页中的超链接
    数组地址详解
    约瑟夫环-源码
    树的基础概念(二)
    二叉树的主要操作
    二叉树的简介及链式结构实现
    树的基础概念
    栈实现数的进制转换
  • 原文地址:https://www.cnblogs.com/chucklu/p/14823135.html
Copyright © 2011-2022 走看看