免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 803 | 回复: 0
打印 上一主题 下一主题

Hash indexes [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-21 08:42 |只看该作者 |倒序浏览

A hash index is built on a hash table and is useful only for exact lookups that use every column in the index.

It stores the hash codes in the index and stores a pointer to each row in a hash table.

hash索引只能用于精确查询。

hash索引存储了hash codekey)和指向对应列的指针。

In MySQL, only the Memory storage engine supports explicit hash indexes. They are the default index type for Memory tables,though Memory tables can have B-Tree indexes too. The Memory engine supports nonunique hash indexes, which is unusual in the database world. If multiple values have the same hash code, the index will store their row pointers in the same hash table entry, using a linked list.

MySQL中只有Memory引擎表支持hash索引——这也是Memory表的默认索引——所以Memory表同时支持hash索引和B-Tree索引。Memory表的hash索引允许键值冲突,当多列的键值相同时,指向这些列的指针会存在同一个hash表入口,并组织成链表方式。

Because the indexes themselves store only short hash values, hash indexes are very compact. The hash value's length doesn't depend on the type of the columns you index——a hash index on a TINYINT will be the same size as a hash index on a large character column.

hash索引的key长度都是一样的,而且都非常短。key长度和索引列类型无关——TINYINT类型和字符类型列的hash索引key长是一样的。

Hash 索引的一些细则:
  • 索引只包含了键值和列指针,所以MySQL还是需要去访问实际的列数据——B-Tree索引可以在叶子节点存储实际的列数据来避免这样的事情。不过幸好只有Memory 表支持Hash索引,所以速度还是很快。

  • 不能用Hash索引来做排序。

  • 不能用Hash索引来做模式匹配查找(通配符),因为需要有完整的列值来计算出Hash key值。

  • Hash索引只能做确定值的查找,如"=""IN()""<=>"<=>的作用是确定两个NULL值是否真的不同)。

  • 在没有键值冲突的情况下,用Hash索引查找是非常快的——有键值冲突时,指针会被组织成单链表,遍历链表很耗时。

  • 键值依靠程序生成,所以在某些特定情况下会产生大量的键值冲突,这是Hash索引的效率就比较低了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP