询问者
SQL Server update 执行为什么会越来越慢?

问题
-
在一个大的事务中,需要 用 update 更新 大概100万条记录,每个更新的数据都要通过一堆计算规则处理,所以无法一批更新
更新前面几条记录的时候非常快(不到1毫秒),但是随着时间的推移,update执行时间越来越长,最后竟然需要 100 毫秒
这是什么原因?
update更新用到了 primary key,更新了大概10个字段,整表只有15个字段,其余5个用作主键
语句基本这样:
update table set
field1 = xxx,
field2 = xxx,
where key1 = ..., key2 = xxx ... key5 = xxx.
SQL Server 是 2014的
全部回复
-
用 profile,可以看到 duration的时间从 1毫秒一直会增加到 100多毫秒
当然实际的执行时间也是越来越慢,这个可以明显感受到
- 已编辑 workwise-temp 2017年7月4日 6:29
-
Hi workwise-temp,
可以查看一下你的查询计划吗,这个要分析查询计划才能判断具体原因。并且在执行update语句的时候监控一下CPU,内存和硬盘I/O的占用情况。
Best Regards,
TeigeMSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com. -
可否将更新语句
update table set
field1 = xxx,
field2 = xxx,
where key1 = ..., key2 = xxx ... key5 = xxx.
改成
update table set
field1 = xxx,
field2 = xxx,
where key1 = ...
update table set
field1 = xxx,
field2 = xxx,
where key2 = xxx
update table set
field1 = xxx,
field2 = xxx,
where key5 = xxx.
专注于.NET ERP/CRM开发框架,C/S架构,SQL Server + ORM(LLBL Gen Pro) + Infragistics WinForms