string(21) "{"docs":[],"count":0}" Mysql嵌套查询与连接查询的效率问题 - 爱码网
bigbitcoin

执行语句如下: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

分类:

技术点:

相关文章: