有个SQL视图为
select a1,a2 from a
union
select b1,b2 from b 
union
select c1,c2 from c 
union
select d1,d2 from d
记录才两万多都要了11秒,怎么能提高效率速度 

解决方案 »

  1.   

    1、没有where,速度会受影响
    2、如果没必要的话,把union改成union all
      

  2.   

    你单独查询四个表需要的多少时间?union 会过滤掉重复的记录
    你可以尝试把union改为union all,时间是否会少一些?
      

  3.   

    可以考虑换个思路:
    每个语句后面跟上where  最后union all连接效率高
      

  4.   


    不需要where 改为union all后还是一样,每个表都有主键
      

  5.   

    估计唯一有用的办法就是索引视图了,没有where,你那个必然是聚集索引扫描
      

  6.   

    1.把union 改成union all
    2.在这视图上加索引
      

  7.   

    是每个查询都搞成一个索引视图,然后之间union