Home >Backend Development >PHP Tutorial >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?

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
WBOYOriginal
2016-12-05 13:44:301506browse

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

Statement:
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