1.在MySQL 中,in 优化思路, 利用left join 来优化,类似如下的查询方式:
select id from a where id in (select id from b )
如这样的查询方式,在大数据量的情况下,查询很慢,需要改写优化sql,那么就可以用left join来优化改写如下格式:
select id from a left join b on a.id =b.id where b.id is not null
2. not in的优化
select id from a where id not in (select id from b )
优化后
select id from a left join b on a.id =b.id where b.id is is null