Home > Database > Mysql Tutorial > body text

When does mysql use indexes?

清浅
Release: 2020-09-15 09:23:29
Original
4961 people have browsed it

The situations where indexes need to be used in MySQL include: when using a link that does not start with a wildcard, when extracting rows from a table when performing a join, and when finding the max or min value of a specified index, etc.

When does mysql use indexes?

When does MySQL use indexes

1. Use >, >=, =, <, <= for a key code , IF NULL and BETWEEN

SELECT * FROM table_name WHERE key_part1=1 and key_part2 > 5;
SELECT * FROM table_name WHERE key_part1 IS NULL;
Copy after login

2. When using LIKE that does not start with a wildcard

SELECT * FROM table_name WHERE key_part1 LIKE &#39;jani%&#39;
Copy after login

3. When extracting rows from another table when performing a join

SELECT * from t1,t2 where t1.col=t2.key_part
Copy after login

4. Find the MAX() or MIN() value of the specified index

SELECT MIN(key_part2),MAX(key_part2) FROM table_name where key_part1=10
Copy after login

5. Use ORDER BY or GROUP BY as the prefix of a key code

SELECT * FROM foo ORDER BY key_part1,key_part2,key_part3
Copy after login

6. Use it in all queries The column is part of the key code

SELECT key_part3 FROM table_name WHERE key_part1=1
Copy after login

Related learning recommendations:mysql tutorial(video)

The above is the detailed content of When does mysql use indexes?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template