Home >Backend Development >PHP Tutorial >Do Mysql's integers need indexes?

Do Mysql's integers need indexes?

WBOY
WBOYOriginal
2016-10-11 14:23:311382browse

Does Mysql field integer type, which is commonly used for sorting and filtering, require an index? I've always been confused.

Reply content:

Does Mysql field integer type, which is commonly used for sorting and filtering, require an index? I've always been confused.

Adding a B-Tree index has the following three advantages
1. It reduces the amount of data that the server needs to scan.
2, can help the server avoid sorting and temporary tables.
3. Random I/O can be turned into sequential I/O.
If the number in the data table is very small, you can not add it first. A simple full table scan is more efficient. For medium to large tables, indexes are very effective. But for extremely large tables, the cost of creating and using indexes will increase. In this case, you can use partitioning technology to query the required set of data instead of matching record by record. Hope it helps you.

It depends on the degree of discreteness of the data. If it is continuous data such as student number, there is no need for an index. For data with a relatively high degree of discreteness such as phone number, you can consider setting an index.

If the amount of data is large, add integer type which is more efficient than characters
The questioner can look at the knowledge of index optimization

Statement:
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