項目中遇到這么個情況:
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)