15 and desc='测试'".这种-6ren">
gpt4 book ai didi

MySQL索引: possible_keys is null but key isn't null

转载 作者:行者123 更新时间:2023-11-29 19:15:23 26 4
gpt4 key购买 nike

今天使用复合索引出现问题,如(name,age,DESC),现在去查询"select * from table ThisTableName where age>15 and desc='测试'".这种情况下,B-Tree索引不符合最左匹配原则,索引possible_keys为null可以理解,但key却显示了复合索引。为什么会这样呢,possible_keys是代表可以使用的索引,如果这个值为null,则key值原则上只能为null。

最佳答案

我认为这个片段来自the MySQL documentation解释一下:

It is possible that key will name an index that is not present in the possible_keys value. This can happen if none of the possible_keys indexes are suitable for looking up rows, but all the columns selected by the query are columns of some other index. That is, the named index covers the selected columns, so although it is not used to determine which rows to retrieve, an index scan is more efficient than a data row scan.

关于MySQL索引: possible_keys is null but key isn't null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42755956/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com