Home > Database > Mysql Tutorial > How efficient is mysql's use of subqueries?

How efficient is mysql's use of subqueries?

coldplay.xixi
Release: 2020-10-09 11:41:01
Original
3003 people have browsed it

mysql subquery efficiency: The efficiency of using subquery [SELECT id,`name` FROM customer where id IN(select DISTINCT(customerid) from searchaccount] is 10 times higher.

How efficient is mysql's use of subqueries?

The efficiency impact of mysql using subqueries

is only the use of id:

explain 
SELECT * from customer where id in(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20)
Copy after login

How efficient is mysqls use of subqueries?

Result:

How efficient is mysqls use of subqueries?

Using subquery:

explain 
SELECT id,`name` FROM customer where id IN(select DISTINCT(customerid) from searchaccount WHERE kfuid=126 AND iskf=1) LIMIT 20
Copy after login

Result:

How efficient is mysqls use of subqueries?

Without subquery Query to achieve the same effect:

explain 
select DISTINCT(customerid) as id,c.name from searchaccount s LEFT JOIN customer c on s.customerid=c.id WHERE s.kfuid=126 AND s.iskf=1 limit 20
Copy after login

How efficient is mysqls use of subqueries?

The efficiency is 10 times the impact.

Related free learning recommendations: mysql tutorial(Video)

The above is the detailed content of How efficient is mysql's use of subqueries?. 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