create table t1(x char(10), y char(10), key hs using hash(x,y)) engine=myisaminsert into t1 values('fdsfd', 'gdfas'),('fds', 'gasd');describe select * from t1 where x>'fd'结果为
1 SIMPLE t1 index hs hs 62 2 Using where; Using index
请问hash索引这是怎么了, 支持范围查找了????????????????????????????

解决方案 »

  1.   

    不支持范围查找   但是并不是说不支持扫描hash索引
    显然扫描hash索引要比扫描表代价小
      

  2.   


    但是describe就是很明确的提示使用了hs这个索引啊
      

  3.   

    mysql> create table t1(x char(10), y char(10), key hs using hash(x,y)) engine=myisam;
    Query OK, 0 rows affected (0.07 sec)
     
    mysql> insert into t1 values('fdsfd', 'gdfas'),('fds', 'gasd');
    Query OK, 2 rows affected (0.17 sec)
    Records: 2  Duplicates: 0  Warnings: 0
     
    mysql> show index from t1;
    +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
    | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
    +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
    | t1    |          1 | hs       |            1 | x           | A         |        NULL |     NULL | NULL   | YES  | BTREE      |         |               |
    | t1    |          1 | hs       |            2 | y           | A         |        NULL |     NULL | NULL   | YES  | BTREE      |         |               |
    +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
    2 rows in set (0.00 sec)MyISAM 用的是B-TREE索引,不支持显式的hash索引,但是可以内部使用自适应HASH索引。memory引擎默认是hash索引。如果是B-TREE索引,一切都好解释了吧?