MYSQL关于Hash索引类型的索引有时会被忽略

标签 mysql indexing hash

我有一个列,其索引类型为 Hash,其值从 1..128

像这样

CREATE INDEX indexName ON myTable (studentType) USING HASH;

有时我们会遇到这样的查询。

Select * from myTable where studentType =1;
Select * from myTable where studentType =2;

这里索引使用得很好,但是我在阅读文档时,有些东西确实引起了我的注意,我想也许我没有很好地理解。

Only whole keys can be used to search for a row. (With a B-tree index, any leftmost prefix of the key can be used to find rows.)

这是否意味着如果我有这样的查询:

Select * from myTable where studentType =2 and status=121;

这里 MySQL 忽略了哈希索引“studentType”?因为where子句使用了除列索引之外的其他列?或者它在示例中所说的内容。

最佳答案

InnoDB没有HASH索引。您的声明已转换为 BTree

这些 BTree 索引中的任何一个都适用于您的最后一个 SELECT:

INDEX(studentType, status)
INDEX(status, studentType)

关于MYSQL关于Hash索引类型的索引有时会被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44828376/

相关文章:

MySQL:选择所有具有最高 ID 的类型

javascript - jQuery 将相同的类添加到两个不同容器中的相同元素索引

excel - SUMIF动态改变求和列

Python pandas.core.frame.Dataframe 索引不正确/如何删除 csv 文件每行末尾的逗号?

ruby - 摘要的 Base-36 表示

mysql - 将 UTF-8 格式的批量 CSV 数据导入 MySQL

php - Laravel Eloquent 检查先前的急切加载关系

c# - 如何获得与 FormsAuthentication.HashPasswordForStoringInConfigFile ("asdf", "MD5") 方法相等的哈希值?

javascript - Express.js(node.js框架)带有sql数据库,无法正确连接文件之间

c# - 将 md5 哈希字节数组转换为字符串