表T(id,type,pid,……)的自关联,该表数据400Wselect a.* from (select * from t where t.type='a') a,(select * from t where t.type='b') b
where a.pid=b.pid请问该如何优化,谢谢!

解决方案 »

  1.   

    select a.*
    from t a
    where a.type='a' and exists(select 1 from t b where b.type='b' and a.pid=b.pid)
      

  2.   

    这样写还慢的话,那只能对type,pid建立索引了
      

  3.   

    1. 对type,pid建立索引
    2. 还慢, 就对表分区
    3. 还不行, 就建索引分区.
    4. 还不行, 那我也不行了.
      

  4.   

    看着LZ提供的sql总感觉奇怪。
    建议LZ贴出范例数据,说清实际需求