56,940
社区成员




数据的量级是 100万
语句可能是这样的:
select * from my_table where a = 1 and (b = 'apple' or b = 'android' ) and c >= 10000 and c <= 200000 and d >= '2014-10-10 12:59:10' order by d desc limit 40;
where的条件可能会因为用户输入而进行增删。
where的查询条件,每一个字段都有一个“单列索引”,没有“联合索引”。
之所以不建立联合索引,是因为两个原因:1.某些查询条件可能会删除。2.某些查询条件是“范围查询”。
现在遇到问题了:这个查询有时候需要很久才能返回数据(几十秒)。请问这样的查询有没有什么优化的方法?
或者说,这种情况下应该搭建Lucene了?
不要用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