[英]Make MySQL use index for sorting, but not in WHERE clause?
I have a query that simplifies to我有一个查询可以简化为
SELECT *
FROM table
WHERE field > 5
ORDER BY field DESC
where field>5
matches more than half the records.其中
field>5
匹配超过一半的记录。 I have an index on field
, but MySQL isn't using it because too many records satisfy the condition.我在
field
上有一个索引,但 MySQL 没有使用它,因为太多记录满足条件。 Is it possible to use the index only for the order, but not the WHERE
clause?是否可以仅将索引用于订单,而不能用于
WHERE
子句?
I guess the simple answer is: there is no point in doing so, even if possible.我想简单的答案是:即使可能,这样做也没有意义。 The database optimizer decides when to use the index depending whether it's going to enhance the performance or not.
数据库优化器决定何时使用索引取决于它是否会提高性能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.