$sql = "select * from pre_common_member_profile as p where destination = '{$user['destination']}' and p.uid <> {$uid} and p.uid > {$huid} and gender = {$displaygender} and uid not in(select fuid from pre_home_friend where uid={$uid}) order by uid";怎么优化一下这条查询语句,是不是效率太低了?请大神赐教~~~~

解决方案 »

  1.   

    p.uid <> {$uid}  不走索引的 uid not in(select fuid from pre_home_friend where uid={$uid})   这个
      

  2.   

    以文本方式贴出 
    explain select ...
    show index from ..
    以供分析。
      

  3.   

    可以根据调整添加序列的方式提供性能吧!explain看看再说
      

  4.   

    1、避免使用select * 如果数据量大会导致网络传输量大,占用网络带宽
    2、把not in的子查询转换为left jion 
    3、建议看一下执行计划,看看是否需要索引方面的优化