Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
不应该';mysql中ref的两个常量是否为类型常量?_Mysql_Indexing_Constants_Ref_Explain - Fatal编程技术网

不应该';mysql中ref的两个常量是否为类型常量?

不应该';mysql中ref的两个常量是否为类型常量?,mysql,indexing,constants,ref,explain,Mysql,Indexing,Constants,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 use

我有以下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\u item\u id是user\u id和item\u id的复合索引。

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

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

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


ref列中的const表示mysql可以使用以前的值在索引中查找内容。

查询必须访问一些数据-ref表示数据由单个值匹配-它不是const的原因是mysql无法对其进行优化-它必须访问一行-这反过来将type设置为ref而不是const应该从
EXPLAIN
添加您的查询看起来非常有效。