项目中遇到这么个情况:

t1表 和 t2表  都是150w条数据,600M的样子,都不算大。

但是这样一句查询 ↓

select * from t1 where phone not in (select phone from t2)


直接就把我跑傻了。。。十几分钟,检查了一下  phone在两个表都建了索引,字段类型也是一样的。原来not in 是不能命中索引的。。。。

 

改成 NOT EXISTS 之后查询 20s ,效率真的差好多。

 select * from t1 
 where  not  EXISTS (select phone from t2  where t1.phone =t2.phone)

 

相关文章:

  • 2021-06-17
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
  • 2022-12-23
  • 2021-12-19
  • 2021-10-01
  • 2021-09-24
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-09
  • 2022-12-23
  • 2021-05-20
  • 2021-10-16
相关资源
相似解决方案