1. Why we need the index 'include' feature?

For SQLServer , the length of all the index key have a limit length as 900 byte.

when you create a index whose keys' total length may exceced 900 byte , such as below

CREATE TABLE GPCUSTEXT(
CUSTNO nvarchar(20),
FIELD_VALUE nvarchar(2000) ,
CREATED_ON datetime ,
CREATED_BY int ,
MODIFIED_ON datetime ,
MODIFIED_BY int ,
EXTCUST_ID int NOT NULL,
METAFIELD_ID int,
CONSTRAINT PK_GPCUSTEXT PRIMARY KEY CLUSTERED (EXTCUST_ID)
)

go

create index GPCUSTEXT_CUSTNO_METAFIELD_ID on gpcomp1.GPCUSTEXT(CUSTNO,METAFIELD_ID,FIELD_VALUE)

you will got as warning saying the data length may exceed the 900 byte
at that situation sqlserver cannot put all key data into the index tree.

or you want to have a LOB column in the index , such as below

CREATE TABLE GPPROB(
PROBLEM_ID int NOT NULL,
CUSTNO nvarchar(20) NULL,
SALESID nvarchar(45) NULL,
PCODE nvarchar(10) NULL,
STATUS nvarchar(100) NULL,
PTEXT nvarchar(max) NULL,
CONSTRAINT PK_GPPROB PRIMARY KEY CLUSTERED (PROBLEM_ID)
)

go

create index GPPROB_CUSTNO_PTEXT on GPPROB(CUSTNO,PTEXT)

you will got an error saying the PTEXT is invalid for index as it is a LOB.

So SQLServer introduced the 'include' feature to go around above
situation.

Also if we updated the 'include' column, the index no need to
re-order due to the 'include' has nothing with the index tree leaf
order.

Vice versa, the SQLServer will not consider the 'include' column
when judge which index need to use.

then execute a query sql as below

select custno,ptext from gpcomp1.GPPROB

Due to the 'include' column , the index
'GPPROB_CUSTNO_PTEXT' have all data needed for the query sql,

so then
sqlserver will only scan the index 'GPPROB_CUSTNO_PTEXT' to get all
data.  It will not access the table.

We only have to consider the 'include' column when the key length is exceed 900 byte or want to include a LOB column to improve the performance.

The include feature of SQL Server Index的更多相关文章

  1. [SQL Server]Index/deadlock

    http://www.cnblogs.com/tintown/archive/2005/04/24/144272.html http://coolshell.cn/ http://blogs.msdn ...

  2. SQL Server Index详解

    最近在进行数据库调优,对索引的使用和其内部的运转一知半解.在园子里看到一篇相关文章非常好.留下印记以便日常查找. http://www.cnblogs.com/xwdreamer/archive/20 ...

  3. 转:Sql Server中的表访问方式Table Scan, Index Scan, Index Seek

    0.参考文献 Table Scan, Index Scan, Index Seek SQL SERVER – Index Seek vs. Index Scan – Diffefence and Us ...

  4. Microsoft SQL Server Trace Flags

    Complete list of Microsoft SQL Server trace flags (585 trace flags) REMEMBER: Be extremely careful w ...

  5. Microsoft SQL Server Version List [sqlserver 7.0-------sql server 2016]

    http://sqlserverbuilds.blogspot.jp/   What version of SQL Server do I have? This unofficial build ch ...

  6. P6 Professional Installation and Configuration Guide (Microsoft SQL Server Database) 16 R1

    P6 Professional Installation and Configuration Guide (Microsoft SQL Server Database) 16 R1       May ...

  7. Sql Server查询性能优化之不可小觑的书签查找

    小小程序猿SQL Server认知的成长 1.没毕业或工作没多久,只知道有数据库.SQL这么个东东,浑然分不清SQL和Sql Server Oracle.MySql的关系,通常认为SQL就是SQL S ...

  8. SQL Server: Top 10 Secrets of a SQL Server Expert

    转载自:http://technet.microsoft.com/en-us/magazine/gg299551.aspx Many companies have downsized their IT ...

  9. SQL Server 2008 R2 SP3 and SQL Server 2008 SP4 are now available!

    时间 2014-10-02 00:00:00 SQL Server Team Blog   原文  http://blogs.technet.com/b/dataplatforminsider/arc ...

随机推荐

  1. QDialog, QFileDialog 和 QDesktopServices 的使用方法

    Qt中的QDialog类是用来生成对话框的类,QFileDialog 类是QDialog的衍生类,主要用来生成打开文件,或是打开文件目录的对话框,或者是保存文件的对话框,下面我们一一来看代码: 1. ...

  2. php函数描述及例子

    /** * xml2array() will convert the given XML text to an array in the XML structure. * Link: http://w ...

  3. Java数组运算

    在使用Java进行程序设计的时候,当为一个long型变量赋值一个整数常量时,如果这个值超过int型数据的取值范围,程序就会出现编译错误,但是有一种情况程序不会出错的,就是将多个int型数据进行算数运算 ...

  4. Ubuntu安装Flash

    第一步:打开视频网站,随意点击一个视频,会提示需要先安装Flash,点击它所提供的链接. 第二步:根据系统选择合适的版本进行下载,有红帽的yum版本,我选择的是tar.gz for other Lin ...

  5. Yii源码阅读笔记(十五)

    Model类,集中整个应用的数据和业务逻辑——验证 /** * Returns the attribute labels. * 返回属性的标签 * * Attribute labels are mai ...

  6. HTML: Css初始化

    相同的元素, 如ul>li,body等元素在不同的瀏覽器下被渲染的效果不同(各個瀏覽器對這些元素的border,margin,padding,font-size等等的初始值不同), 要讓他們表現 ...

  7. changing a pointer rather than erasing memory cells

    Computer Science An Overview _J. Glenn Brookshear _11th Edition In a data structure based on a point ...

  8. jsonObject jsonarray

    1.JAR包简介 要使程序可以运行必须引入JSON-lib包,JSON-lib包同时依赖于以下的JAR包: commons-lang.jar commons-beanutils.jar commons ...

  9. nRF51822之app_button控制uart的开启和关闭

    为什么要使用app_button来控制uart的开启和关闭 还是先上datesheet中uart开启的时候需要HFCLK,需要消耗大量大电流.所以在我们需要的时候需要通过io来通知nrf51822开启 ...

  10. 图算法(一)——基本图算法(BFS,DFS及其应用)(2)

    2)DFS 深度优先搜索总是对最近发现的节点v的出发边进行搜索,直到该节点的所有出发边都被发现 一旦节点v的所有出发边都被发现,搜索回溯到v的前驱结点进行 实现细节:时间戳 每一个结点有一个发现时间和 ...