Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the efficiency effects of mysql after using subquery efficiency

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail what the efficiency impact is after the use of sub-query efficiency of mysql. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

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

The efficiency impact of mysql after using subquery

Just take advantage of id:

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

Results:

The subquery is used:

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

Results:

No subqueries are needed 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

Efficiency is a ten-fold effect.

On the use of mysql sub-query efficiency after what efficiency impact is shared here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report