一点一点的定位打印日志,最后发现,居然是一条使用了exists的sql语句,查询就用了2秒,也就是说时间都花在这个上了,其它的基本都可以忽略了,语句如下:select*from TERM t where exists(select t2.TERM_ID from ASS_POST_TERM t2 where ...
select*from book b where exists(select 1 from class where b.bookid=id);select*from book b where bookid in(select id from class);它的运行方式是这样的,类似于俩个for循环 for select*from class for select*from book where book....
像下面这个子查询SQL,就可以被自动优化了[root@yejr.run]>explain select*from t1 where exists(select nu from t2 where t1.seq=t2.nu and nu>=10);id|select_type|table|type|possible_keys|key|key_len|ref|rows|filtered|Extra|+-+-+-...
MySQL系列-优化之精准解读in和exists 1.解读in和exists 这两个关键字的区别主要是在于子查询上面,in是独立子查询,exists是相关子查询,例如:用in查询有员工的部门:select dept_name from dept where id in(select dept_id from emp);用...