我的sql写法:
select a.* from record a where a.id not in(select b.rec_id from offline_record);
数据量:record大约2w条   offline_record大约4w条
这样很慢,不知道为什么(record.id和offline_record.rec_id都建了索引的)网上查了not in优化,进行了以下尝试:
1.select a.* from record a inner join offline_record b on a.id!=b.rec_id
2.select a.* from record a where not exists(select b.rec_id from offline_record b where b.rec_id=a.id)
1语句我知道!=这个地方应该有问题,但不知道该怎么改进,现在的写法不行,查不出来数据,
2语句查询很慢,并且查的时候过一段时间就会卡死
网上还有left join方式来对not in进行改进,我也试了 ,没用,查的时候很卡
希望给帮帮忙啦,给个解决办法我 ,万分感谢了!PS:mysql是默认配置,没有进行配置优化,不论是配置优化的建议或sql语句优化的建议都可