编程技术

mysql子查询效率:利用子查询【SELECT id,`name` FROM customer where id IN(select DISTINCT(customerid) from searchaccount】效率是10倍级的影响。

mysql利用子查询效率怎么样_编程技术_亿码酷站插图

mysql利用子查询后的效率影响

仅仅是利用id:

explain 
SELECT * from customer where id in(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20)

69f1540e642cc7256ba2cf311ec955f.png

结果:

e53585ef356b22898013167017c3efe.png

利用了子查询:

explain 
SELECT id,`name` FROM customer where id IN(select DISTINCT(customerid) from searchaccount WHERE kfuid=126 AND iskf=1) LIMIT 20

结果:

cc5856396bf17f93674c575529addc6.png

不用子查询,达到同样的效果:

explain 
select DISTINCT(customerid) as id,c.name from searchaccount s LEFT JOIN customer c on s.customerid=c.id WHERE s.kfuid=126 AND s.iskf=1 limit 20

a8291751931de96852121ca5a0ecde2.png

效率是10倍级的影响。

mysql利用子查询效率怎么样
—–文章转载自PHP中文网如有侵权请联系admin#tyuanma.cn删除

mysql服务器无效怎么办

云服务器推荐