javascript - Putting a huge user ID array in in in a multi-table association query statement causes the query to take too long. How to optimize it?

WBOY
Release: 2023-03-03 11:14:01
Original
1479 people have browsed it

In the multi-table association query statement, placing a huge user ID array in in causes the query time to be too long. How to optimize it?

1. The query statement is as shown below, and the execution time is 147.4ms.

javascript - Putting a huge user ID array in in in a multi-table association query statement causes the query to take too long. How to optimize it?

Reply content:

In the multi-table association query statement, placing a huge user ID array in in causes the query time to be too long. How to optimize it?

1. The query statement is as shown below, and the execution time is 147.4ms.

javascript - Putting a huge user ID array in in in a multi-table association query statement causes the query to take too long. How to optimize it?

WHERE id IN (1,2,3) is equivalent to WHERE id = 1 OR id = 2 OR id =3
OR There are so many conditions, even if there is an index on the id, it is normal to be slow.

The root cause of this problem is unreasonable table structure design. Optimizing queries is also a temporary solution rather than a permanent solution
So don’t be too anxious when designing the structure
In addition, use EXPLAIN more often

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!