Get the App
SLTechnology News&Howtos  ›  Database  › 

What are the specific differences between btree and hash indexes in MySQL

Shulou Source: shulou.com Published: 2022-06-01 18:29:19 11月09日 Update

The following brings you about the specific differences between btree and hash indexes in MySQL. If you are interested, let's take a look at this article. I believe it will be helpful for you to read the specific differences between btree and hash indexes in MySQL.

(1) Hash indexes can only satisfy "=", "IN" and "" queries, but cannot use range queries.

Because the Hash index compares the Hash value after the Hash operation, it can only be used for equivalent filtering, not for range-based filtering, because the size relationship of the Hash value processed by the corresponding Hash algorithm cannot be guaranteed to be exactly the same as before the Hash operation.

(2) Hash indexes cannot be used to avoid sorting data.

Because the Hash index stores the Hash value after Hash calculation, and the size relationship of the hash value is not necessarily the same as the key value before the Hash operation, the database cannot use the index data to avoid any sort operation.

(3) Hash indexes cannot be queried by partial index keys.

For a composite index, the Hash index calculates the Hash value by combining the index keys and then calculating the Hash value together, rather than calculating the Hash value separately, so the Hash index cannot be utilized when querying through one or more of the first index keys of the composite index.

(4) Hash indexes can not avoid table scans at any time.

As we already know, the Hash index stores the Hash value of the Hash operation result and the corresponding row pointer information in a Hash table after the index key is calculated through Hash. Because different index keys have the same Hash value, even if you take the number of records that meet a certain Hash key value, you can not directly complete the query from the Hash index, or you have to access the actual data in the table to compare and get the corresponding results.

(5) when a large number of hash values are equal, the performance of Hash index is not necessarily higher than that of B-Tree index.

For index keys with low selectivity, if you create a Hash index, there will be a large amount of record pointer information associated with the same Hash value. In this way, it will be very troublesome to locate a record, which will waste many visits to table data, resulting in poor overall performance.

Read the details above about the specific differences between btree and hash indexes in MySQL, and whether you have gained anything. If you want to know more about it, you can continue to follow our industry information section.

Tags: Index data operation query time combination information size performance pointer result range sort different low same following interest content actual Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Huawei MySQL Xiaomi macOS