mysql database storage structures

mysql database storage structures

The difference between B-tree and hash indexes

B-tree index

The index is stored in the order, so that, according to the B-tree index, can be returned directly with the order data, but this data is only the information contained in the index column. Thus sequential I / O
  • Applies to:

    • Exact match

    • Range matching

    • Leftmost match

Hash index

Hash index column values ​​+ data row pointers: therefore the need to look to find the pointer according to the data, resulting in a random I / O
  • Suitable for:
    • Exact match
  • Not suitable:

    • Fuzzy matching
    • Range matching
    • Not sorted
  • Excerpt summary of other people:

    • 1, hash index satisfies only "=", "IN" and "<=>" query, the query can not be used range

      Because the hash index comparison is often hash hash value after the operation, it can only be filtered equivalent, based on the discovery range can not, because of the size relationship between the hash value of the hash algorithm after treatment, does not guarantee that the pre-treatment correspondence relation hash size.

    • 2, hash index can not be used for data sorting operation

      Since the hash stored in the index are calculated after a hash value, and the size relationship between the hash value is not necessarily the same as the previous hash value calculation, so the database can not use the hash value of the index sort operation.

    • 3, for the combination of the index, the index when calculating the Hash value Hash Hash value is calculated and then combined with the index key combination, rather than a single

      When only calculated Hash value, the query index through the front of one or several of the composite index key, the index Hash can not be utilized.

    • Performance will not necessarily higher than the index B-Tree 4, Hash index encountered large Hash values ​​are equal.

      For relatively low selectivity index key, if you create an index Hash, then there will be a large number of records stored in the pointer information associated with a Hash value. In this way to locate one of the logs will be very troublesome, will waste many visits to the table data, resulting in poor overall performance.

Summary: Hash apply in pinpoint small-scale, large, and do not need to sort data in columns, no fuzzy query, useful range query

Guess you like

Origin www.cnblogs.com/tyler-bog/p/10961883.html