gpt4 book ai didi

mysql - 这不应该使用索引而不是 where 吗?

转载 作者:行者123 更新时间:2023-11-29 00:59:42 25 4
gpt4 key购买 nike

EXPLAIN EXTENDED SELECT  `member`.`id` ,  `member`.`name` 
FROM `member`
WHERE `member`.`last_active` > '1289348406'

显示以下输出,尽管 last_active 上有一个索引....它不应该说 index 而不是 where 吗?

id  select_type table   type    possible_keys   key key_len ref rows    filtered    Extra
1 SIMPLE member range last_active last_active 4 NULL 2 100.00 Using where

最佳答案

Using index意味着查询根本不接触表:

Using index

The column information is retrieved from the table using only information in the index tree without having to do an additional seek to read the actual row. This strategy can be used when the query uses only columns that are part of a single index.

由于您的索引并未涵盖所有字段,因此这是不可能的。

当然会使用索引本身(因为访问类型是 range ),但它仍然需要在表中进行行查找以检索 name 的值和 id .

(last_active, name, id) 上创建覆盖索引如果你想看Using index .

关于mysql - 这不应该使用索引而不是 where 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4140254/

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