高性能MySQL笔记-第5章Indexing for High Performance-002Hash indexes
一、
1.什么是hash index
A hash index is built on a hash table and is useful only for exact lookups that use every column in the index.
For each row, the storage engine computes a hash code of the indexed columns, which is a small value that will probably differ from the hash codes computed for other rows with different key values. It stores the hash codes in the index and stores a pointer to each row in a hash table.
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.
2.hash index数据结构
-- hash index的数据结构
CREATE TABLE testhash (
fname VARCHAR(50) NOT NULL,
lname VARCHAR(50) NOT NULL,
KEY USING HASH(fname)
) ENGINE=MEMORY;
3.hash index的缺点
Because the indexes themselves store only short hash values, hash indexes are very compact. As a result, lookups are usually lightning fast. However, hash indexes have some limitations:
• Because the index contains only hash codes and row pointers rather than the values themselves, MySQL can’t use the values in the index to avoid reading the rows.Fortunately, accessing the in-memory rows is very fast, so this doesn’t usually degrade performance.
• MySQL can’t use hash indexes for sorting because they don’t store rows in sorted order.
• Hash indexes don’t support partial key matching, because they compute the hash from the entire indexed value. That is, if you have an index on (A,B) and your query’s WHERE clause refers only to A , the index won’t help.
• Hash indexes support only equality comparisons that use the = , IN() , and <=> operators (note that <> and <=> are not the same operator). They can’t speed up range queries, such as WHERE price > 100 .
• Accessing data in a hash index is very quick, unless there are many collisions (multiple values with the same hash). When there are collisions, the storage engine must follow each row pointer in the linked list and compare their values to the lookup value to find the right row(s).
• Some index maintenance operations can be slow if there are many hash collisions.For example, if you create a hash index on a column with a very low selectivity (many hash collisions) and then delete a row from the table, finding the pointer from the index to that row might be expensive. The storage engine will have to examine each row in that hash key’s linked list to find and remove the reference to the one row you deleted.
The InnoDB storage engine has a special feature called adaptive hash indexes. When InnoDB notices that some index values are being accessed very frequently, it builds a hash index for them in memory on top of B-Tree indexes. This gives its B-Tree indexes some properties of hash indexes, such as very fast hashed lookups. This process is completely automatic, and you can’t control or configure it, although you can disable the adaptive hash index altogether.
高性能MySQL笔记-第5章Indexing for High Performance-002Hash indexes的更多相关文章
- 高性能MySQL笔记-第5章Indexing for High Performance-001B-Tree indexes(B+Tree)
一. 1.什么是B-Tree indexes? The general idea of a B-Tree is that all the values are stored in order, and ...
- 高性能MySQL笔记-第5章Indexing for High Performance-004怎样用索引才高效
一.怎样用索引才高效 1.隔离索引列 MySQL generally can’t use indexes on columns unless the columns are isolated in t ...
- 高性能MySQL笔记-第5章Indexing for High Performance-005聚集索引
一.聚集索引介绍 1.什么是聚集索引? InnoDB’s clustered indexes actually store a B-Tree index and the rows together i ...
- 高性能MySQL笔记-第5章Indexing for High Performance-003索引的作用
一. 1. 1). Indexes reduce the amount of data the server has to examine.2). Indexes help the server av ...
- 高性能MySQL笔记 第6章 查询性能优化
6.1 为什么查询速度会慢 查询的生命周期大致可按照顺序来看:从客户端,到服务器,然后在服务器上进行解析,生成执行计划,执行,并返回结果给客户端.其中“执行”可以认为是整个生命周期中最重要的阶段. ...
- 高性能MySQL笔记 第5章 创建高性能的索引
索引(index),在MySQL中也被叫做键(key),是存储引擎用于快速找到记录的一种数据结构.索引优化是对查询性能优化最有效的手段. 5.1 索引基础 索引的类型 索引是在存储引擎层而 ...
- 高性能MySQL笔记 第4章 Schema与数据类型优化
4.1 选择优化的数据类型 通用原则 更小的通常更好 前提是要确保没有低估需要存储的值范围:因为它占用更少的磁盘.内存.CPU缓存,并且处理时需要的CPU周期也更少. 简单就好 简 ...
- 高性能MySQL笔记-第1章MySQL Architecture and History-001
1.MySQL架构图 2.事务的隔离性 事务的隔离性是specific rules for which changes are and aren’t visible inside and outsid ...
- 高性能MySQL笔记-第4章Optimizing Schema and Data Types
1.Good schema design is pretty universal, but of course MySQL has special implementation details to ...
随机推荐
- gulp插件之-----转化es6代码到es5 取消严格模式 remove "use strict" directive
Installation npm install babel-plugin-transform-remove-strict-mode && yarn add babel-plugin- ...
- Thinkphp5.0 获取新增数据的ID
// 方法1 insertGetId方法新增数据并返回主键值使用getLastInsID方法: Db::name('user')->insert($data); $userId = Db::na ...
- 完成一个servlet 就要在web.xml里面配一个映射,这样就有一个路径供我们 使用????? servlet从页面接收值?
最后,最容易忘记的是:在dao层中 调用xml里的删除sql语句 后面需要人为加上事务提交.一定要! sqlSession.commit();//jdbc是自动提交,但是mybatis中不是自动提交的 ...
- Thinkphp 自定义404页面
一. 手册->调试->异常处理 在公共config.php 中加入: 'TMPL_EXCEPTION_FILE' => '/Public/404.html', //访问不存在的跳转 ...
- unity3d___UGui中如何创建loading...进度条
http://blog.sina.com.cn/s/blog_e82e8c390102wh2z.html 实现方法:通过Image组件中Image Type属性中Fill Amount,通过代码改变F ...
- 什么是 PCB 的压适孔
引用 AMOBBS 1 再举一个高成本控制的例子:有类PCB产品对孔径要求极度严格,这类孔叫压适孔,这类孔的作用类似于显卡内存条的插座,能刚刚好被元件插上,而且元件不会掉,PTH的压适孔公差要求为-0 ...
- python 集合和深浅copy
#1数据类型的补充#2.集合set#3.深浅copy 补充:str --> bytes s.encode('gbk')bytes --> str s.decode('gbk') 1.数据类 ...
- maven工程编译成jar包
在pom文件的project节点下增加build节点,mvn package即可 <build> <plugins> <plugin> <artifactId ...
- rabbitmq -- networking
RabbitMQ大名鼎鼎, 其networking 部分经常被众多Erlang 程序员, 爱好者分析. 小的时候就见到很多人写过这方面的blog, 比如: 1, http://www.blogjava ...
- echo 的部分用法
echo “内容” > 文件名 (会覆盖文件里的所有内容) echo “内容” >> 文件名 (追加内容到文件里,会另起一行写入) 如果您阅读过此文章有所收获,请为我顶一个,如果文章 ...