mysql中的两个consts不应该是一个类型const吗?

时间:2012-08-28 01:52:05

标签: mysql indexing const ref explain

我有以下MySQL查询

explain select item_id from items use index(user_item_id) where user_id=9 and item_id=10000

返回以下内容

id  select_type table   type    possible_keys   key             key_len   ref           rows    Extra
1   SIMPLE      items   ref     user_item_id    user_item_id    8         const,const   1       Using index

为什么类型是ref而不是const?

user_item_id是user_id和item_id的综合索引。

1 个答案:

答案 0 :(得分:2)

高性能MySql将ref类型查找描述为“这是一个返回与单个值匹配的行的索引访问”

当添加单词const时,它被描述为“优化部分查询并将其转换为常量”

因此,似乎MySQL需要能够首先从索引中找到行

ref列中的consts意味着mysql可以使用以前的值来查找索引中的内容。

相关问题