有一张大表A, 记录用户登录日志, 5千万级数据
表中 有uid 作为用户ID字段, 非主键, 有建立索引, 不是唯一字段, 约有 1千万个不同的UID另给了一个5K个 UID, 让查出这5K个UID中没有在A表出现过的UID
求一个优化查询 SQL

解决方案 »

  1.   

    select * from 另给了一个5K个 where not exists (select 1 from  A where UID=另给了一个5K个.UID)或者select 另给了一个5K个.* from 另给了一个5K个 left join A on 另给了一个5K个.UID=a.UID where a.UID is null
    第一个理论上速度会略快一点儿。
      

  2.   

    你的SQL语句是什么
    EXPLAIN SQL语句
      

  3.   

    A 5000万级别
    B 5k
    select *from B where not exits (select * from A where  B.uid=A.uid)