exists与in效率分析

--A表大,B表小,用A表的索引,B表会被全扫描,效率高
select * from A where ID in (select ID from B)

--A表小,B表大,用B表的索引,A表会被全扫描,效率高
select * from A as TA where exists(select 1 from B as TB where TB.ID = TA.ID)

--not in 全表扫描
--not exists 会用到索引

这篇

另外一篇

猜你喜欢

转载自www.cnblogs.com/Cengjianwei/p/10750191.html