【问题标题】:MYSQL about Hash index type index is ignore sometimesMYSQL 关于 Hash 索引类型索引有时被忽略
【发布时间】:2017-12-03 08:18:45
【问题描述】:

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

像这样

CREATE INDEX indexName ON myTable (studentType) USING HASH;

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

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

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

只能使用整个键来搜索一行。 (使用 B-tree 索引,可以使用键的任何最左边的前缀来查找行。)

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

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

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

【问题讨论】:

    标签: mysql indexing hash


    【解决方案1】:

    InnoDB 没有 HASH 索引。你的声明变成了BTree

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

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

    【讨论】:

      猜你喜欢
      • 2010-10-31
      • 2010-12-02
      • 2017-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多