mysql in 子句 vs 一次提交多次删除
我有大约 100K 条记录,我必须运行以下查询:
delete from users where name in #{String}
其中字符串可以是这种形式的 100K 字符串:Joe,Kate 等。
为了提高性能,最好运行上述语句或在循环中删除一条记录session.commit();
到底是什么?
已编辑
每个值只能有一条记录
I have about 100K records that I have to run for the following query:
delete from users where name in #{String}
where the string could be 100K strings of this form: Joe,Kate etc.
For performance is it better to run the above statement or delete one record in a loop with one session.commit();
in the end?
EDITED
There could be only one record for each value
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您可以创建要运行的批量查询,那么将其分成多个批次很可能是最快的:
等等。
如果表中已有名称,您可以这样做:
If you can create batches of queries to run then breaking it up into batches would most likely be the fastest:
etc..
If you have the names in a table already you can just do this:
最好不要使用这样的语句!
查询优化器将花一天的时间来解析这样的查询。我建议使用一些临时表来连接,或者要删除的记录有共同点的其他 WHERE 子句?
It would be better not to use such statements!
The query optimizer will have a field day parsing such a query. I suggest using some temporary table to join against, or some other WHERE-clause that the records to be deleted have in common?