我已经在s1_date中创建了一个索引,但是此查询仍然非常慢(15 s),但是当我删除“由s1_date desc排序”时,它的速度更快(大约10毫秒) 这是查询:
SELECT * FROM `bucket_1` WHERE type = 'type1' AND (batch_number1 like '' OR batch_number2 like '' OR batch_number2 like '' OR batch_number3 like '' OR batch_number4 like '' OR batch_number5 like '') order by s1_date desc limit 10
答案 0 :(得分:1)
这是查询的噩梦。 s1_date上的索引将无济于事,因为查询引擎必须在进行任何排序之前首先应用谓词type = 'type1' AND (batch_number1 like '' OR batch_number2 like '' OR batch_number2 like '' OR batch_number3 like '' OR batch_number4 like '' OR batch_number5 like '')
,而这些谓词将是大部分工作。尤其是那些OR确实会使索引混乱,这意味着使查询快速运行将是一个问题。
查看是否可以用其他方式表示数据,这样就不必使用这些OR。