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. loadView、viewDidLoad及viewDidUnload的关系

      标题中所说的3个方法,都是UIViewController的方法,跟UIViewController的view属性的生命周期息息相关.接下来我会一一阐述它们的作用以及它们之间的联系. loadVi ...

  2. mysql主从配置脚本

    PASSWD=123456USER=rootREP_HOST=10.10.10.70REP_PORT=3306REP_USER=slaveREP_PASSWD=123456@REP_FILE=mysq ...

  3. 记sql语句空格带来的问题

    在做分页的时候,引用了一个分页类.在一条sql语句出发生错误,没查出数据,代码如下 $sql="select * from sw_goods".$page->limit; 正 ...

  4. 用户提交的cookie提交时为什么传不到服务器

    cookie与session跨域登陆代码(ie6,ie7,firefox)frameset里面,也就是里面的frame是来自第三方站点(不同ip或不同域名),那么默认情况下ie会自动禁用这些站点的co ...

  5. 一个Java方法覆盖的小问题

    class SuperClass{ public SuperClass() { System.out.println("superclass "); show(); } publi ...

  6. 基本Java数据类型

    一.整型:java中的基本数据类型byte,占用1个字节,8位   取值范围:0000 0000 ~ 1111 1111 (-128 ~ 127)   为什么不是:0000 0000 ~ 1111 1 ...

  7. windows 下安装Yii2 高级版本

    1.  首先安装 Composer 2.  执行  composer global require "fxp/composer-asset-plugin:~1.1.1" 3. 执行 ...

  8. 使用PHP获取网站Favicon的方法

    使用PHP获取网站Favicon的方法 Jan022014 作者:Jerry Bendy   发布:2014-01-02 23:18   分类:PHP   阅读:4,357 views   20条评论 ...

  9. ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/

    https://en.wikipedia.org/wiki/Base64 The Base64 index table: Value Char   Value Char   Value Char   ...

  10. php安装,mysql安装

    先安装mysql 下载地址:http://dev.mysql.com/downloads/mysql/5.6.html#downloads 选择“Source Code”,用已经注册好的oracle账 ...