執行語句如下:select count(DISTINCT l1) from t1 where l1 in(select l2 from t2 where l3='xxx') 感覺速度很慢(幾十秒),
但是單獨執行子查詢select l2 from t2 where l3='xxx'或者去掉子查詢這個直接執行select count(DISTINCT l1) from t1都比較快。
將語句改成join的形式效果就快很多(毫秒級別),修改后語句如下:select count(DISTINCT l1) from t1 inner join t2 where t1.l1=t2.l2 and t2.l3='xxx'。
具體原因分析可見:https://www.cnblogs.com/Bccd/p/6607515.html