不要用or
改用union all试试
select * from
(
select * from (select * from my_table where    a = 1  and  b = 'apple'   and  c >= 10000 and  c  <=  200000   and   d >= '2014-10-10 12:59:10'   order by d desc limit 40)a
union all
select * from (select * from my_table where    a = 1  and  b = 'android'   and  c >= 10000 and  c  <=  200000   and   d >= '2014-10-10 12:59:10'   order by d desc limit 40)b
)c
limit 40

解决方案 »

  1.   

    说错了,用 UNION ALL
      

  2.   

    楼上几位说的都是对的,使用union all 是个不错的选择
      

  3.   

    这个查询优化的空间的很小了。每一列都建立了单列索引,在实际运行这个语句时,也只能用到一个索引。建议LZ 在动态拼接这个 SQL时 , 把那些没有条件的列也拼出来,比如 colA = colA 这样,这些列是尽可能多的被用户使用到的列。有点乱,欢迎回复本帖子讨论。
      

  4.   

    楼上说的对,使用“UNION ALL”替换"OR"即可,添加会增加或删除 ,在程序中判断添加或删除即可 。