我有一个包含 10 列的表,该表中有数千/数百万行。
在某些情况下,我想一次更新超过 10K 条记录。目前我的场景代码按顺序工作,
for i in (primary key ids for all records to be updated)
executeupdate(i)
我的想法是,我不会运行相同的查询 10K 次,而是将所有 id 添加到字符串中并运行单个更新查询,例如,
executeupdate(all ids)
实际的数据库查询可以是这样的,
假设我有主键 ID,例如
10001,10002,10003,10004,10005
所以在第一种情况下我的查询会像
update tab1 set status="xyz" where Id="10001"
update tab1 set status="xyz" where Id="10002"
update tab1 set status="xyz" where Id="10003"
update tab1 set status="xyz" where Id="10004"
update tab1 set status="xyz" where Id="10005"
我的批量更新查询将是这样的,
update tab1 set status="xyz" where id in ("10001","10002","10003","10004","10005")
所以我的问题是,通过批量更新我会得到任何性能改进(执行时间)
或者总查询执行时间将与每个记录的索引扫描和更新相同?
注意:我使用 DB2 9.5 作为数据库
Thanks.