日期:2014-05-17  浏览次数:20858 次

为什么sql中使用in语句后速度狂降?
语句一:select   *   from   tab   where   条件一
语句二:与语句一完全相同,只是增加了一个   in(1,2,5...20)子句

为什么语句二比语句一要花几倍的时间呢?

------解决方案--------------------
因为执行计划改变了

把in改成exists

例如:

select a.* from table_a a where a.name exists(select b.name from table_b b where b.id=a.id);