in与exists和not in 与 not exists的区别

1、in 与 exists:

  外表大,用IN;内表大,用EXISTS;

  原理:

  用in:外表使用了索引,直接作hash连接;

  用exists:内表使用了索引,外表作loop循环再进行匹配;

2、not in与not exists:

  性能:not in不走索引,所以一般都用not exists;

  区别:还有一点区别就是,not in字段为null的不进行筛选出来;而使用not exists即可;

  这也就是说有时定义字段,用not null比较好了,这样也能避免not in查询出错。  

原文地址:https://www.cnblogs.com/gendway/p/10784065.html