In a multi-table join query statement, a large array of user IDs is placed in the in statement, resulting in a long query time. how can I optimize it? 1. for example, the execution time of a query statement is 147.4 ms.
In a multi-table join query statement, a large array of user IDs is placed in the in statement, resulting in a long query time. how can I optimize it?
1. for example, the execution time of a query statement is 147.4 ms.
Reply content:
In a multi-table join query statement, a large array of user IDs is placed in the in statement, resulting in a long query time. how can I optimize it?
1. for example, the execution time of a query statement is 147.4 ms.
WHERE id IN (1, 2, 3)EquivalentWHERE id = 1 OR id = 2 OR id = 3
If there are so many OR conditions, it is normal that the index on the id is slow.
The root cause of this problem is that the table structure design is unreasonable, and the optimization of queries is also a temporary problem.
So do not worry too much when designing the structure.
In addition, use EXPLAIN