select * from tablename where mykey=123 || mykey=456可以优化吗?
求解释,求优化原理。

解决方案 »

  1.   

    在mykey上建立索引
    select * from tablename where mykey=123 
    union all
    select * from tablename where mykey=456
      

  2.   

    求原理。
    如果不建立索引2楼的会快些吗?
    mysql数据库。
      

  3.   

    不会,建立索引就是要提高查询速度
    explain sql语句,看看结果
      

  4.   

    索引是双刃剑,提高查询速度,在UPDATE、DELETE、INSERT时要更新索引,在有索引的情况下:
    select * from tablename where mykey=123  
    union all
    select * from tablename where mykey=456
    快些
      

  5.   

    谢谢!最终决定用union,索引是肯定要的。