一次优化小例子
?
--accountRecord表主鍵是tradeno varchar(50)類型,沒有其他合適的索引可用--數據量8000W,新建索引也不太現實--用此種方法,本來執行一次需要十秒左右,這種方法只需要一秒--第一次執行的時候取一次最小的tradeno,以后每次都會更新最小tradeno,大大提升性能!!!declare @i int =0declare @tradeno varchar(50) while @i<10beginif @i=0select @tradeno=min(tradeno) from accountRecord where wCompleteTime is null and CompleteTime is not nullselect @tradeno=min(tradeno) from accountRecord where tradeNo>=@tradeno and wCompleteTime is null and CompleteTime is not nullupdate accountRecord set wCompleteTime =CompleteTime where 1=1and tradeNo in (select top 20000 tradeNo from accountRecord where tradeNo>=@tradeno and wCompleteTime is null and CompleteTime is not null order by tradeNo asc) set @i=@i+1PRINT CAST(@i AS VARCHAR(4))+' '+@tradeno+' '+convert(varchar(25),getdate(),121)+REPLICATE(' ',4000)WAITFOR DELAY '0:00:02'end?
轉載于:https://www.cnblogs.com/davidhou/p/5629276.html
總結
- 上一篇: 43、Java动态代理一——动态类Pro
- 下一篇: git 提交各种情况下的处理方式