Home > Database > Mysql Tutorial > body text

What is the difference between in and or in mysql

WBOY
Release: 2021-12-23 11:15:01
Original
6037 people have browsed it

Difference: 1. In performs a hash connection query through the parent query table and the child self-query table, or performs a loop on the parent query table and then queries the child query table; 2. When there is no index or primary key In this case, as the amount of data behind in or or increases, the execution efficiency of or will decrease significantly, but the execution efficiency of in will not decrease significantly.

What is the difference between in and or in mysql

The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.

What is the difference between in and or in mysql

Do data comparison, tens of millions of levels of data

In sql statements The difference between in and or is: different operations, different suitability, and different execution efficiency.

1. Different operations

1. in: in is a hash connection between the parent query table and the child self-query table.

2. or: or performs a loop on the parent query table, and queries the child query table each time the loop loops.

2. Suitable for different 5261

1. in: in is suitable for situations where the child query table has more data than the parent query table.

2. or: or is suitable for situations where the child query table has less data than the parent query table.

3. Different execution efficiency

1. In: In the absence of an index, as the amount of data behind in increases, the execution efficiency of in will not drop much.

2. or: In the absence of an index, as the amount of data behind or increases, the execution efficiency of or will decrease significantly.

If the columns where in and or are located have indexes or primary keys, there is no difference between or and in, and the execution plan and execution time are almost the same.

If the columns where in and or are located do not have indexes, the performance difference will be huge. In the absence of an index, as the amount of data behind in or or increases, the efficiency of in will not drop much, but the performance of or will drop significantly as the number of records increases

Therefore When defining the efficiency of in and or, another condition should be added, that is, whether the column is indexed or whether it is a primary key. If there is an index or primary key, there is no difference in performance. If there is no index, the performance difference is not a little bit!

Recommended learning: mysql video tutorial

The above is the detailed content of What is the difference between in and or in mysql. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!