我有一个完全空白的自定义表(DatabaseLogFixLog),只有一个字段/列名为“refRecId”。我将它加入SysDatabaseLog(日志)。计划是批量更新SysDatabaseLog,当我更新SysDatabaseLog时,我将插入我更新的行的recId。我的SysDatabaseLog里面有370万条记录。我已经尝试了下面的notexists加入和外连接。我的代码出了什么问题?两者都完全锁定了我的系统,调试器不会进入循环。
外部加入:
updateCounter = 10;
while select forupdate log
order by CreatedDateTime, RecId
outer join databaseLogFixLog
where databaseLogFixLog.RefRecId != log.RecId
{
counter++;
if (counter > updateCount)
break;
info(strfmt("%1", counter));
}
info(strfmt("Done updating %1", counter));
Notexists加入:
updateCounter = 10;
while select forupdate log
order by CreatedDateTime, RecId
notexists join databaseLogFixLog
where databaseLogFixLog.RefRecId == log.RecId
{
counter++;
if (counter > updateCount)
break;
info(strfmt("%1", counter));
}
info(strfmt("Done updating %1", counter));
答案 0 :(得分:1)
我认为我不会使用“forupdate”关键字循环这么大的数据集,而是使用一个表缓冲区进行循环(log),另一个用于更新(logUpdate)。
我可以想象系统在循环浏览3.7毫米记录时会挂起,当它运行查询时,你必须等到它最终进入while-select。
此外,请确保RefRecId在表上有索引,因此数据库引擎不会运行全表扫描,尝试在databaseLogFixLog中查找行。
答案 1 :(得分:1)
你的两个连接不等同,你的外连接是完全错误的。
你存在加入会工作,但它必须排序你的日志记录(370万),女巫将需要一些时间。此外,它还必须检查您是否存在logFixLog
记录(对于370万中的每一个),您需要RefRecId
字段上的索引才能加快速度。
如果您想要速度,请删除order by
子句。
您还可以尝试添加firstfast
关键字,它有时可以提供更快的初始结果(但如果与order by
结合使用很少)。
最后,选择要更新的字段,尤其是避免容器字段,因为此字段不与其他字段一起存储。