update400万条数据的效率

liumei1229 2007-07-24 05:03:24
update a
set a.groupid = b.groupid
from dbo.ns_bssgp_liu724 a, templiu724 b
where a.ci_lac=b.ci_lac and a.ci_rac=b.ci_rac and (a.tlli=b.tlli or a.tlli=b.local_tlli or a.tlli=b.foreign_tlli)
and (b.time_stamp-a.time_stamp)>=-10000000 and a.groupid is null

这条语句运行了1个小时还没有出结果.
在上面的基础上添加了索引,并且去掉了or语句(见下面的程序),运行了36分钟,请问还可以优化效率吗?

create index liu1 on dbo.ns_bssgp_liumei2(ci_lac,ci_rac,tlli,time_stamp)
create index liu2 on templiu7241(ci_lac,ci_rac,tlli,time_stamp)
update a
set a.groupid = b.groupid
from dbo.ns_bssgp_liumei2 a, templiu7241 b
where a.groupid is null and a.ci_lac=b.ci_lac and a.ci_rac=b.ci_rac and a.tlli=b.tlli
and (b.time_stamp-a.time_stamp)>=-10000000
...全文
189 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
liumei1229 2007-07-25
  • 打赏
  • 举报
回复
像海阔天空那样修改后,竟然1分多钟就运行完了,不可思议
liumei1229 2007-07-25
  • 打赏
  • 举报
回复
索引是根据
where a.groupid is null and a.ci_lac=b.ci_lac and a.ci_rac=b.ci_rac and a.tlli=b.tlli
and (b.time_stamp-a.time_stamp)>=-10000000
来建立的,where字句中用到多少个字段,我的索引就建多少个字段
昵称被占用了 2007-07-24
  • 打赏
  • 举报
回复
另外,索引怎么建的?


昵称被占用了 2007-07-24
  • 打赏
  • 举报
回复
and (b.time_stamp-a.time_stamp)>=-10000000
应该改成
and a.time_stamp)>=b.time_stamp+10000000

22,206

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧