MySQL文档中有一句话不太理解

请问一下
mysql文档中:
https://dev.mysql.com/doc/ref...

下面这句话中有一部分我不太能理解,求各位帮忙

The index may also be used even if the ORDER BY does not match the index exactly, as long as all unused portions of the index and all extra ORDER BY columns are constants in the WHERE clause. If the index does not contain all columns accessed by the query, the index is used only if index access is cheaper than other access methods.

其中 as long as 那句要怎么理解呢?
我个人的理解是:

只要索引没有在order by出现的列和order by出现但是不在索引中的列在where语句中都是是常量“的意思吗

特别是 all extra ORDER BY columns额外的 order by 列要怎么理解。

阅读 1.5k
1 个回答
SELECT * FROM t1
  WHERE key_part1 = constant
  ORDER BY key_part2;

这里all extra ORDER BY columns are constants in the WHERE clause其实就是指key_part1,官方文档把这个key_part1分不同的角度做了解释,对于索引是没命中的列,对于order by是额外的列。能理解什么情况下可利用索引优化排序即可。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题