A brief discussion on the efficiency of MySQL subquery union and in

A brief discussion on the efficiency of MySQL subquery union and in

Recent product testing found a problem that when the number of concurrent calls is less than 10, the response time can be maintained within 100 milliseconds. However, when the number of concurrent requests reaches 30, the response time exceeds 1 second. This is unacceptable, the requirement is to run 100 concurrent requests in 1 second.

After testing, it was found that the time was mainly consumed in one of the storage processes. I went through the statements of the stored procedure one by one and found no obvious unreasonableness. Because MySQL itself cannot provide millisecond-level time, I googled a MySQL time function that can provide milliseconds, did some testing, and made a positioning. It was found that it was one of the statements, which looked like this:

 select .... from A, B where .....and A.id in (select id from C where ...);

The in subquery statement produces very few results, just a few. There is no problem explaining this statement. There is no problem with single test. But problems arise when the number of concurrent requests is large.

Made a change:

 select ... from A,B,(select ... from C where ...) S where ....;

After another test, the performance has improved significantly. The response speed of 50 concurrency and 10 concurrency is almost the same.

In MySQL, MySQL may suggest changing to using subquery union instead of in. It has not been experimented with before. Now I finally see the efficiency. Of course, we can't believe it all. It still depends on your own application. It would be best to do some testing and experimenting.

Summarize

The above is all the content of this article about the efficiency of MySQL subquery union and IN. I hope it will be helpful to everyone.

Interested friends can refer to:

Several important MySQL variables

Detailed explanation of the code between the MySQL master library binlog (master-log) and the slave library relay-log

MySQL database development specifications [recommended]

If you have any questions, please leave a message and we can discuss together. I also hope that friends will support the 123WORDPRESS.COM website!

You may also be interested in:
  • Detailed analysis and optimization of Mysql multi-table joint query efficiency
  • Detailed explanation of the principles and usage examples of MySQL join query, union query, and subquery
  • Which is faster among MySQL full-text index, joint index, like query, and json query?
  • Analysis of MySQL multi-table joint query operation examples
  • Summary of four situations of joint query between two tables in Mysql
  • Popular explanation of several MySQL joint queries
  • Introduction to the use of MySQL joint query UNION and UNION ALL
  • Solution to the error problem when using UNION and Order by in Mysql joint query
  • MySQL multi-table joint query returns the content of a table implementation code
  • Detailed explanation of MySQL joint query optimization mechanism

<<:  Detailed explanation of how to pass password to ssh/scp command in bash script

>>:  js implements the algorithm for specifying the order and amount of red envelopes

Recommend

Do you know what are the ways to jump routes in Vue?

Table of contents The first method: router-link (...

Analysis and treatment of scroll bars in both HTML and embedded Flash

We often encounter this situation when doing devel...

Summary of 10 amazing tricks of Element-UI

Table of contents el-scrollbar scroll bar el-uplo...

Example code of vue custom component to implement v-model two-way binding data

In the project, you will encounter custom public ...

A detailed discussion of components in Vue

Table of contents 1. Component Registration 2. Us...

JavaScript implements checkbox selection function

This article example shares the specific code of ...

Win10 configuration tomcat environment variables tutorial diagram

Before configuration, we need to do the following...

How to connect to virtual machine MySQL using VScode in window environment

1. Virtual Machine Side 1. Find the mysql configu...

A brief discussion on read-only and disabled attributes in forms

Read-only and disabled attributes in forms 1. Rea...

Common ways to optimize Docker image size

The Docker images we usually build are usually la...

Introduction to Docker Quick Deployment of SpringBoot Project

1. Install Docker First open the Linux environmen...

Interviewers often ask questions about React's life cycle

React Lifecycle Two pictures to help you understa...