码迷,mamicode.com
首页 > 数据库 > 详细

mysql查询优化

时间:2020-06-11 22:09:20      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:sql查询   必须   表数   sel   exist   等价   where   表数据   查询优化   

select * from a where id in (select id from b)

等价于:

for select id from b

for select 8 from a where a.id = b.id

当b表数据必须小于a表数据时,in优于exists

select * from a where exists (select 1 from b where b.id = a.id)

等价于:

for select * from a 

for select * from b where b.id = a.id 

防止exists优于in

mysql查询优化

标签:sql查询   必须   表数   sel   exist   等价   where   表数据   查询优化   

原文地址:https://www.cnblogs.com/saber-xi/p/13096018.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!