Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.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 非聚集索引在不同列类型上的性能_Sql_Performance_Sql Server 2008_Indexing - Fatal编程技术网

Sql 非聚集索引在不同列类型上的性能

Sql 非聚集索引在不同列类型上的性能,sql,performance,sql-server-2008,indexing,Sql,Performance,Sql Server 2008,Indexing,int列上的非聚集索引是否比decimal或datetime列上的非聚集索引性能更高?在某些方面:是 一个INT只有4个字节,因此SQL Server中的单个8K页面上可以容纳更多的INTs DATETIME使用8个字节-因此单个页面上存储的DATETIME值较少,或者对于相同数量的DATETIMEs,您需要更多的页面,因此获得更多的磁盘I/O,从而降低性能 差异的大小取决于更详细的测量,然而,对于数百万行以下的任何内容,差异很可能是可以忽略的。如果您的查询确实受益于DATETIME列上的索引,

int
列上的非聚集索引是否比
decimal
datetime
列上的非聚集索引性能更高?

在某些方面:是

一个
INT
只有4个字节,因此SQL Server中的单个8K页面上可以容纳更多的
INT
s

DATETIME
使用8个字节-因此单个页面上存储的
DATETIME
值较少,或者对于相同数量的
DATETIME
s,您需要更多的页面,因此获得更多的磁盘I/O,从而降低性能


差异的大小取决于更详细的测量,然而,对于数百万行以下的任何内容,差异很可能是可以忽略的。如果您的查询确实受益于
DATETIME
列上的索引,我会毫不犹豫地添加它(再说一次:除非您处理的是数百万行表……那么您可能需要更详细的调查)

许多人也忽略了SMALLDATETIME,它与INT的宽度相同,如果亚分钟精度不重要(通常不重要),它可以作为DATETIME的合适替代品。