0
点赞
收藏
分享

微信扫一扫

SQL server 系统优化--通过执行计划优化索引(3)

执行时间要7205ms,语句如下:    

select top 30 this_.id as id10_0_, this_.objid as objid10_0_, this_.objname 
as objname10_0_, this_.mid as mid10_0_, this_.logtype as logtype10_0_, this_.logdesc as logdesc10_0_, this_.submitor as submitor10_0_, this_.submitdate as submitdate10_0_, 

this_.submittime as submittime10_0_, this_.submitip as submitip10_0_, this_.col1 as col11_10_0_,this_.col2 as col12_10_0_, this_.col3 as col13_10_0_ from log this_ where  not exists (select 'X' from Delobj del where del.objid=this_.id and del.objtable='Log')  order by this_.submitdate desc, this_.submittime desc

  执行sql语句的执行计划:

  

SQL server 系统优化--通过执行计划优化索引(3)_聚集索引

46万行数据。排序的成本很高,我们发现是通过:  

[dbo].[log].submitdate 降序, [dbo].[log].submittime 降序

重构聚集索引。

   是必须在(submitdate,submittime)建立聚集索引,由于前期在设计表时的不合理,造成了时间字段教长,有18个字节,大大超过了8个字节的datetime类型,不太适合建立聚集索引。

适当提高速度

  总结:

  1,字段类型和长短的是很重要,不然在后续修改和优化是很困难。   

    2,对与聚集索引选择一般在需要排序,进行范围选择和group by等字段上建立

 



举报

相关推荐

0 条评论