我有一个列,其索引类型为 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/