首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

mysql中hash索引存在的奇怪的有关问题

2012-05-15 
mysql中hash索引存在的奇怪的问题create table t1(x char(10), y char(10), key hs using hash(x,y)) engi

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'

结果为


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

热点排行