Index 3: Hash index and index BitMap

Hash index Principle:
hash index is the index key by the hash function, the hash value calculation result and the corresponding row pointer information storage Bucket.
Quote: '' hash indexes (hash index) based on a hash table implementation, only an exact match query the index of all columns to be effective. For each row of data, the storage engine are calculated for all the indexed columns a hash code (hash code), the 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. For the same hash, using the list of conflict resolution. Similar hashmap. Because the structure of the index is very compact, so hash indexes inquiry soon ''

keys -------> Buckets ---------> entries loaded into the memory
as compared with B + tree, hash index key value query directly Buckets the corresponding information (hash algorithm, to give the hash value hash index may be sorted so that once positioned on the hash array, its efficiency is high), not like b + tree traversal from the root to a leaf node, reducing the number of disk I / O.

defects hash index:
1 only meet the '=' and 'in', do not range queries (hash index equivalence comparison only supports queries, including =, the iN (), <> (Note <> and <=> different operation). does not support any range queries, for example. price the WHERE> 100.)
hash index because the underlying hash table, the order is not associated with data stored in a hash table, so he does not find a suitable range, if you need to find a full range table scan, he is only suitable for scanning full value
because the index value calculation will need to hash value and row pointer information -> Bucket, so the query or the equivalent from Bucket query.
2. The hash index data is not in accordance with the index value is stored in the order, so it can not be used for sorting.
Because the index is stored Hash value after elapsed Hash Hash calculated Hash value and the magnitude relationship and values are not necessarily exactly the same as before the Hash operation, so the database can not use the index data to avoid any sort of operation;

3. Ha Xisuo lead index column does not support partial matching to find, because the hash index is always the hash value is calculated using the entire contents of the indexed columns.
4. hash index contains only the row pointer and a hash value, without storing the field value, the value of the index can not be used to avoid reading lines.
5.
When the hash value is repeated and large quantity of data is very large, which is not a high retrieval efficiency Btree index.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 all of the row pointer linked list, line by line comparison, until you find all the qualifying rows.
If the hash conflict many words, some of the cost of index maintenance operations will be high. For example, if a low selectivity (many hash collisions) in the column to establish a hash index, then when you delete a row from the table, the storage engine needs through each row in the list corresponds to the hash value, and to find delete the corresponding reference line, the more conflict, the greater the cost

6.Hash index can not be avoided at any time table scan
Hash index after the Hash operation by the index keys, the Hash value and the Hash operation result corresponding to the row pointer information Hash stored in a table, the values are different due to the presence of the same Hash index keys, even if the number of records satisfying take a Hash key value data, can not be completed queries directly from the Hash index, or to access the actual table comparing corresponding data, and the corresponding results.

Released six original articles · won praise 18 · views 3422

Guess you like

Origin blog.csdn.net/qq_41627514/article/details/104261711