日期:2014-05-16  浏览次数:20779 次

mysql中hash索引存在的奇怪的问题
create table t1(x char(10), y char(10), key hs using hash(x,y)) engine=myisam

insert 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索引这是怎么了, 支持范围查找了????????????????????????????


------解决方案--------------------
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索引,一切都好解释了吧?