聚集索引遇到的性能问题(查询分析器试验)
背景:做的是userId+sdate的聚集索引,userId在前
select * from test where datediff(day,sdate,'2006-1-1')=0 and userId='01'
后由于发现性能很差,便在查询分析器中做实验
当实现
select * from test where datediff(day,sdate,'2006-1-1')=0 and userId='01'
select * from test where datediff(day,sdate,'2006-1-2')=0 and userId='01'
select * from test where datediff(day,sdate,'2006-1-3')=0 and userId='01'
也即变化sdate,保持userId不变时,性能很好,
而当
select * from test where datediff(day,sdate,'2006-1-1')=0 and userId='01'
select * from test where datediff(day,sdate,'2006-1-1')=0 and userId='02'
select * from test where datediff(day,sdate,'2006-1-1')=0 and userId='03'
性能却慢了一倍多的时间
如果在where中把sdate和userId的位置对调也是这样
由于我在实际中的例子是按照
select * from test where datediff(day,sdate,'2006-1-1')=0 and userId='01'
select * from test where datediff(day,sdate,'2006-1-1')=0 and userId='02'
select * from test where datediff(day,sdate,'2006-1-1')=0 and userId='03'
来的,所以只能上来问下大家,谢谢
...全文
相关推荐
聚集索引与非聚集索引的区别
一种索引,该索引中键值的逻辑顺序决定了表中相应行的物理顺序。 聚集索引确定表中数据的物理顺序。聚集索引类似于电话簿,后者按姓氏排列数据。由于聚集索引规定数据在表中的物理存储顺序,因此一个表只能包含一个聚集索引。但该索引可以包含多个列(组合索引),就像电话簿按姓氏和名字进行组织一样。
SQL Server 聚集索引和非聚集索引的区别分析
聚集索引:物理存储按照索引排序 非聚集索引:物理存储不按照索引排序
sql 聚集索引和非聚集索引(详细整理)
主要介绍了聚集索引和非聚集索引的相关知识,比较详细整理了一些知识点,需要的朋友可以参考下
sqlserver 聚集索引和非聚集索引实例
sqlserver 聚集索引和非聚集索引实例,学习sqlserver索引的朋友可以参考下。
索引介绍聚集索引和非聚集索引
关于索引的介绍,以及b+树结构图,两种索引性能比较,索引优化建议


