mysql - mysql 中 ref 的两个常量不应该是一个类型常量吗?

标签 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     user_item_id    user_item_id    8         const,const   1       Using index

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

user_item_id 是 user_id 和 item_id 的复合索引。

最佳答案

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

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

所以看来MySQL首先需要能够从索引中找到行

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

关于mysql - mysql 中 ref 的两个常量不应该是一个类型常量吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12151805/

相关文章:

java - 我想用 Lucene 读取索引中的单个术语

go - 为什么io.EOF不是常数?

c++ - 如何使用 lambda 避免代码重复 const 和非常量集合处理

mysql - NodeJS MySQL 异步调用阻止进程退出

php - 在此服务器上找不到请求的 URL/blog/CodeIgniter_2.2.0/posts/post/5

php - Elasticsearch 在映射时更改日期格式

java - Apache 坚果 : Manipulating the DOM before parsing

php - 无法使用PHPExcel将Excel中的数据导入到phpMySql

language-agnostic - 是否也可以通过索引访问来实现链表?

C#静态和常量有什么区别?