Home > Database > Mysql Tutorial > How to create a hash index in mysql

How to create a hash index in mysql

PHPz
Release: 2023-05-30 08:37:05
forward
1894 people have browsed it

Explanation

1. If the storage engine does not support hash index and you want to improve the performance brought by hash index, you can simulate InnoDB to create a hash index.

2. Create a pseudo-hash index based on B-tree. This is not the same as a real hash index. Because B-Tree is still used to search, but the hash value is used instead of the key itself. Just manually specify the hash function in the where clause of the query.

Example

For example, if you need to save a large number of URLs, you need to retrieve them based on the URLs. If you use B-Tree to store URLs, the stored content will become larger.

select id from url where url = "www.baidu.com";
Copy after login

If you delete the index on the original url column, add an indexed url_crc column, and use crc32 as the hash function, you can use the following method to query:

select id from url where url = "www.baidu.com" and url_crc=CRC32("www.baidu.com");
Copy after login

The above is the detailed content of How to create a hash index in mysql. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template