The include feature of SQL Server Index
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的更多相关文章
- [SQL Server]Index/deadlock
http://www.cnblogs.com/tintown/archive/2005/04/24/144272.html http://coolshell.cn/ http://blogs.msdn ...
- SQL Server Index详解
最近在进行数据库调优,对索引的使用和其内部的运转一知半解.在园子里看到一篇相关文章非常好.留下印记以便日常查找. http://www.cnblogs.com/xwdreamer/archive/20 ...
- 转: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 ...
- Microsoft SQL Server Trace Flags
Complete list of Microsoft SQL Server trace flags (585 trace flags) REMEMBER: Be extremely careful w ...
- 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 ...
- 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 ...
- Sql Server查询性能优化之不可小觑的书签查找
小小程序猿SQL Server认知的成长 1.没毕业或工作没多久,只知道有数据库.SQL这么个东东,浑然分不清SQL和Sql Server Oracle.MySql的关系,通常认为SQL就是SQL S ...
- 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 ...
- 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 ...
随机推荐
- 用 Freemarker 生成 word 文档(包含图片)
1. 用word写一个需要导出的word模板,然后存为xml格式. 2. 将xml中需要动态修改内容的地方,换成freemarker的标识符,例如: <w:p wsp:rsidR="0 ...
- TinyMCE在线编辑器使用方法初探
首先,下载TinyMCE包,地址:http://www.tinymce.com/ 然后将下载后的包解压,放置到一个文件夹下,创建一个html文件,并在其中书写如下代码: <!DOCTYPE ht ...
- .net 开发的奇淫巧计
随机数 Random random = new Random(( int)DateTime .Now.Ticks & 0x0000FFFF); 如何让ASP.NET Web API显示完整的错 ...
- freeswitch
FreeSWITCH 是一个电话的软交换解决方案,包括一个软电话和软交换机用以提供语音和聊天的产品驱动.FreeSWITCH 可以用作交换机引擎.PBX.多媒体网关以及多媒体服务器等.可以用作一个简单 ...
- hrbust oj 1526+2028 树状数组
冒泡排序中 如果一个数的后面的某个数和这个数不符合排序规则 那么这个数就会在未来的某次冒泡中与那个数进行交换 这里用到了 树状数组求逆序数的办法来做 需要注意的是2028并不可以改完数组大小后直接套1 ...
- Cent OS 6.6 下安装mysql(5.5.20)和 PHP(5.3.10)
0.准备步骤(没有连接网络的 linux): 挂载光盘.让网络 yum 源失效.修改光盘 yum 文件.安装 c 语言编译器 gcc. 1.MySQL(5.5.20) 下载 mysql 5.5.20 ...
- 20145235 《Java程序设计》第6周学习总结
教材学习内容总结 10.1 InputStream与OutputStream 串流设计的概念 Java将输入/输出抽象化为串流,数据有来源及目的地,衔接两者的是串流对象. 从应用程序角度来看,如果要将 ...
- maven库文件所在目录
C:\Documents and Settings\jgzhang2\.m2\repository
- mysql入门问题
1.给列设置默认时间 在创建表的图形化界面,不能直接用函数sysdate()或者now()来设置默认当前时间,要用sql脚本创建的话就可以 IF NOT EXISTS `tb_1` THENBEGIN ...
- Linux命令echo -e
在Linux命令中 echo -e 这个参数e是什么意思. echo –e “I will use ‘touch’ command to create 3 files.” 这里参数e的作用是什么 ma ...