mySQL快速删除大量行
我有两个表,我需要第一个表中未出现在第二个表中的所有行。
这些表可以被销毁,因为它们是从其他表转储的。
第一个表有约 5700 万行。第二个表有大约 1000 万行。
由于显而易见的原因,这两个查询都花费了很长时间,请帮助我更快地完成此操作。
SELECT * FROM db.first WHERE id NOT IN (SELECT id FROM db.second)
DELETE FROM db.first WHERE id IN (SELECT id FROM db.second)
编辑:我不需要第二个表中的任何记录,我只需要第一个表中出现但第二个表中未出现的行。
I have two tables, I need all rows from the first that don't appear in the second.
The tables can be destroyed as they're dumps from other tables.
First table has ~57million rows. Second table has ~10million rows.
Both of these queries are taking forever for obvious reasons, please help me do this quicker.
SELECT * FROM db.first WHERE id NOT IN (SELECT id FROM db.second)
DELETE FROM db.first WHERE id IN (SELECT id FROM db.second)
Edit: I don't need any records from the second table, I only need rows that appear in the first table that don't appear in the second table.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能会快得多:
使用 join:和删除
It would probably be a lot quicker using joins:
and the delete: