IN与EXISTS和INNER JOIN执行效率


主要是查询日志里面的数据个数,过滤掉一些非法ip,手机上的,因此存在非法ip一说,呵呵

log_pv里面的数据有3000多,而t_ipnetlist表里有移动网关ip45000条左右。

select count(id) from log_pv where (issue_id=1042 or issue_id=1044 ) and  exists (select ip from t_ipnetlist where log_pv.ip=t_ipnetlist.ip)

select count(id) from log_pv where (issue_id=1042 or issue_id=1044 ) and  log_pv.ip in (select ip from t_ipnetlist )

select count(id) from log_pv as t1 INNER JOIN  t_ipnetlist as t2 on  t1.ip=t2.ip where t1.issue_id=1042 or t1.issue_id=1044

in数据量少效率还可以,数据量大就效率低
exists的效率依赖于匹配度。
inner join效率比较稳定。

你可能感兴趣的:(IN与EXISTS和INNER JOIN执行效率)