[英]Limit query size to control transaction log size
This query causes our transaction log to grow to 25GB. 该查询使我们的事务日志增长到25GB。 The database is in SIMPLE mode.
数据库处于简单模式。
INSERT INTO updbl.dbo.PopulationRelatives
( personid,
personsex,
relativeid,
relativesex,
degree,
relationship,
maternalpaternal )
SELECT DISTINCT
personid = relative1,
relative1sex,
relative2,
relative2sex,
degree,
relationship = Rel1Rel2,
maternalpaternal
FROM UPDBwork.dbo.DegreeRelationship
By looping I was able to limit the growth to 8GB. 通过循环,我能够将增长限制为8GB。
SELECT @PID = 0, @BatchSize = 1000000, @ROWCOUNT = 0
SELECT @MaxPID = MAX(relative1) FROM updbwork.dbo.DegreeRelationship
WHILE @PID < @MaxPID+@BatchSize
BEGIN
INSERT INTO updbl.dbo.PopulationRelatives
( personid,
personsex,
relativeid,
relativesex,
degree,
relationship,
maternalpaternal )
SELECT DISTINCT
personid = relative1,
relative1sex,
relative2,
relative2sex,
degree,
relationship = Rel1Rel2,
maternalpaternal
FROM UPDBwork.dbo.DegreeRelationship
WHERE relative1 BETWEEN @PID+1 AND @PID+@BatchSize
SET @PID = @PID + @BatchSize
CHECKPOINT
END
This isn't the best strategy as each loop produces a different number of rows depending on the DISTINCT values. 这不是最佳策略,因为每个循环根据DISTINCT值产生不同数量的行。 Unfortunately there is no good ID to partition the data on.
不幸的是,没有很好的ID可以对数据进行分区。 Is there some way I could control for the size of each group?
有什么办法可以控制每个小组的人数吗? I was thinking of adding TOP(X) but the engine would still have to do a large calculation to satisfy the DISTINCT statement.
我当时正在考虑添加TOP(X),但是引擎仍然必须进行大量计算才能满足DISTINCT语句。 A cursor would be great but again, how do I find my DISTINCT values?
游标会很棒,但是再次,我如何找到我的DISTINCT值? I am just hoping for some brain storming here.
我只是希望在这里有些头脑风暴。 Thanks.
谢谢。
Sounds like bulk operation... if changing the recovery model is an option temporarily change it to bulk-logged. 听起来像批量操作...如果选择更改恢复模型,则暂时将其更改为批量记录。 Here is a link that may be of help: http://technet.microsoft.com/en-us/library/ms175987(v=SQL.105).aspx
这是一个可能有帮助的链接: http : //technet.microsoft.com/zh-cn/library/ms175987(v=SQL.105).aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.