Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 在SQL Server上的非聚集索引中包含许多列可以吗?_Sql Server_Tsql_Indexing - Fatal编程技术网

Sql server 在SQL Server上的非聚集索引中包含许多列可以吗?

Sql server 在SQL Server上的非聚集索引中包含许多列可以吗?,sql-server,tsql,indexing,Sql Server,Tsql,Indexing,举以下例子: CREATE NONCLUSTERED INDEX IX_Address_PostalCode ON Person.Address (PostalCode) INCLUDE (AddressLine1); GO 如果我在包含列表中包含更多列,如: CREATE NONCLUSTERED INDEX IX_Address_PostalCode ON Person.Address (PostalCode) INCLUDE (AddressLine1, Addr

举以下例子:

CREATE NONCLUSTERED INDEX IX_Address_PostalCode  
ON Person.Address (PostalCode)  
INCLUDE (AddressLine1);  
GO  
如果我在包含列表中包含更多列,如:

CREATE NONCLUSTERED INDEX IX_Address_PostalCode  
ON Person.Address (PostalCode)  
INCLUDE (AddressLine1, AddressLine2, City, StateProvinceID, Latitude, Longitute, Zip, Country, etc... );  
GO   
这需要更多的磁盘空间吗

或者换一种说法:包含在
INCLUDE
列表中的数据是否在索引的叶节点上重复?

是。


这正是包含的原因:牺牲一些空间,但使(某些)查询在需要包含列时不必进行键查找,而是从索引本身获取它们。

非聚集索引中的所有内容都是重复数据,无论是在键中还是在包含列中。这样的索引会有很大的开销。您可能会在这里找到一个更深入的问题答案:在规模的最末端,包括索引中的每一列实际上意味着您将表存储两次,行的顺序不同。值得指出的是,您不仅牺牲了空间,而且在修改上花费了更多的I/O。当然,这些权衡是否值得,这取决于它。