mysql- hash indexes

The hash index is valid hash table implementation, only an exact match queries based on an index of all columns. For each row of data, the storage engine are calculated for all the indexed columns a hash code, a hash code is a small value, and key values ​​of different rows computed hash codes are not the same. Hash index all the hash code stored in the index, while preserving a pointer to each row of data in a hash table.
 
 
In mysql Only Memory engine explicit support hash indexes. This is also the default index type memory engine tables, memory engine also supports B-Tree index. It is worth mentioning that the memory is to support non-unique hash index
 
 
 
Hash index limit
1, only the hash value comprises a hash index and row pointers, the field value is not stored, the value of the index can not be used to avoid reading lines. However, the line speed access memory quickly, so in most cases, this influence on performance is not obvious.
2, hash index data is not in accordance with the index value stored sequentially, so it can not be used for sorting.
3. hash indexes do not support partial matching index column to find, because the hash index is always the hash value is calculated using the network all indexed columns. For example, data columns (A, B) on the establishment of a hash index, if the query only data column A, you can not use the index.
4, hash indexes only support the equivalent comparison queries, including =, in (), <=> (note <> and <=> are different operations). Does not support any range queries, for example, where price> 100
5, access hash index data very quickly, unless there are Duoha Xi conflict (different index column values ​​there is the same hash value). When the hash collision occurs, the storage engine must traverse the linked list so the row pointer, line by line comparison, until you find all the qualifying rows
6, if the hash collision many words, why some of the cost of index operations will be high. For example, the establishment of a hash index, then when deleting a row from the table, the storage engine needs through each row in the list corresponds to the hash value if a low selectivity (many hash collisions) column, locate and delete corresponding to the reference line, the more conflict, the greater the cost
 
 
Processing hash collision
To avoid conflicts, and the hash value must substituting values ​​corresponding column where conditions. If not specifically refer to a query like, for example, only statistics the number of records (inaccurate), may not be brought into the column values ​​directly using CRC32 () the hash value of the query.

Guess you like

Origin www.cnblogs.com/kevinleerunqing/p/12034342.html