现有 A、B 两个表,A 是用户表(100 万条),B 是绑定设备的表(50 万条),现在要删去过期用户的绑定设备 按正常操作, 直接用 delete from B where B.userid in (select userid from A where 用户会员过期) 这个语句删除会超时,请问怎么操作,sql 咋写效率比较高?
1
roscoecheung1993 2019 年 2 月 18 日
sql 不精,yy 一下,用表连接会不会好些? where B.userid = A.userId and 用户会员过期
|
2
lzz2394677796 2019 年 2 月 18 日 via iPhone
delete from B where B.userid in (select userid from (select userid from A where 用户会员过期) as tmp)
效率百倍?! |
3
sunnyadamm 2019 年 2 月 18 日 via Android
加索引,left join,几千条一提交
|
4
des 2019 年 2 月 18 日 via Android
MySQL 的 where in 效率不好,特别是子查询的时候
这个好多人说过了 |
5
qa2080639 2019 年 2 月 18 日
in 里面子查询 不使用索引 会很慢
|
6
c6h6benzene 2019 年 2 月 18 日 via iPhone
试试 inner join ?
|
7
xuanbg 2019 年 2 月 18 日
delete b
from b join a on a.userid = B.userid where a.用户会员过期 |