有同事说我的sql语句存在效率问题我原来的语句是:
select a_id form t_a where a_id in (select o_id from t_o where t=3 and s=10)同事说a_id虽然是主键也是索引,但是并未起到索引作用经过优化后的语句:
select a_id form t_a where a_id in (select o_id from (select o_id from t_o where t=3 and s=10) t)各位的看法如何?

解决方案 »

  1.   

    explain select ... 看一下执行计划,对比分析一下就知道了。
      

  2.   

    分析一下不就知道了,explain执行计划不就知道了。
      

  3.   

    mysql中应该严禁出现in(子查询)的情况 !!select a_id form t_a where a_id in (select o_id from t_o where t=3 and s=10)
    改成
    select  a_id from t_a A,t_o B
    where A.a_id=B.o_id and B.t=3 and B.s=10;
      

  4.   

    explain试一下此方法应该效率比in高。
      

  5.   

    http://bbs.csdn.net/topics/310109377
     [求证&散分]MySQL 中 where id in (1,2,3,4,...) 的效率问题讨论