delete from table where id in(数万条记录)

刚从数据库中 delete from table where id in(1,2,3,4) 没问题,速度很快

但是一旦加上子查询 如delete from table where id in(select id from table2)  就非常慢,有时候跑了一整天都没动静,

最后搜索查询了下  in子查询这个样的语句在mysql5.6之前一直是禁止使用的 效率极差 改成表连接的方式

采用如下方式即可:

delete a from table1 a inner join table2 b on a.id=b.id
速度就快了很多。

delete from table where id in(delete from table where id in(1,2,3,4) 数万条记录)

你可能感兴趣的:(mysql)