而循环问题 [英] While Loop Question

查看:60
本文介绍了而循环问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

表结构:每个ID都有十亿个ALTID。我们有一个存档任何ID的过程,ALTID超过3个月作为过期ID。下面是使用的while循环,但Delete过程需要花费大量时间才能运行。有什么建议在使用while循环或任何其他方法时使用任何替代方法
来处理如此庞大的数量?在此删除过程中,交易日志会被填满。

Table Structure: Each ID has Billion ALTID's. We have a process to Archive any ID's, ALTID's more than 3 months as Expired ID's. Below is the while loop used but the Delete process is taking lot of time to run. Any suggestions to use any alternate approach to handle such huge volumes while using while loop or any other approach ? Transaction log gets filled up during this delete process.

ID      AltID的     日期  Col1 Col2 .....

ID     AltID     Date  Col1 Col2.....

1    100

1    100

1    300

1   300

1    8000000

1    8000000

2    400

2   400

2    50505005

2   50505005

sami

推荐答案

当您像这样进行批处理时,索引必须支持批处理。

When you do batching like this, it is imperative that the batching is supported by indexes.

也就是说,必须有一个索引来支持这个查询:

That is, there must be an index to support this query:

DELETE TOP(1000)FROM ArchiveAud WHERE TypeID = 1 AND EntID in(SELECT AltIDFROM# OldArchiveAlerts)

DELETE TOP(1000) FROM ArchiveAud WHERE TypeID=1 AND EntID in (SELECT AltIDFROM #OldArchiveAlerts)

这将是一个索引(TypeId,EndID)。

That would an index on (TypeId, EndID).


这篇关于而循环问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆