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 ...
随机推荐
- log4j与commons-logging,slf4j的关系
前面有一篇日志中简单的介绍了 log4j,同时也介绍了它与commons-logging的关系,但是突然冒出来一个slf4j,并且slf4j有取代commons-logging的趋势,所以,我们可以推 ...
- 常用NuGet插件
1.Install-Package System.Data.SQLite 2.Install-Package FluentData
- POJ 2104&HDU 2665 Kth number(主席树入门+离散化)
K-th Number Time Limit: 20000MS Memory Limit: 65536K Total Submissions: 50247 Accepted: 17101 Ca ...
- Windows中杀死占用某个端口的进程
Windows中杀死占用某个端口的进程 netstat -ano | findstr //列出进程极其占用的端口,且包含 80 tasklist | findstr taskkill -PID < ...
- [杂谈]交通工具orca card
How and Where to Use the ORCA Card The Microsoft ORCA card provides unlimited rides on all buses, tr ...
- PHP / JavaScript / jQuery 表单验证与处理总结: 第①部分 PHP 表单验证与处理
PHP VERSION = 5.3.10 一.关于 $_REQUEST PHP 文档关于 $_REQUEST 的说明: 说明 默认情况下包含了 $_GET,$_POST 和 $_COOKIE 的数组. ...
- Web 在线文件管理器学习笔记与总结(11)获取文件夹信息 (12)返回上一级操作
(11)获取文件夹信息 文件夹没有修改操作. index.php: <?php require 'dir.func.php'; require 'file.func.php'; require ...
- PHP pear安装
PHP pear安装 Posted on 2012-07-06 10:19 bug yang 阅读(5787) 评论(0) 编辑 收藏 转自:http://wangye.org/blog/archiv ...
- Yii源码阅读笔记(一)
今天开始阅读yii2的源码,想深入了解一下yii框架的工作原理,同时学习一下优秀的编码规范和风格.在此记录一下阅读中的小心得. 每个框架都有一个入口文件,首先从入口文件开始,yii2的入口文件位于we ...
- 利用EXCEL表实现网页数据采集到MYSQL数据库
先复制页面表格数据到EXCEL中,比如 2012-1-4 52.7 52.7 49 48.83 190007 9506968 2012-1-5 48.86 49.79 45.72 45.6 62325 ...