About sql Optimization

now I have an array, which contains about 100000 of the data, all personId,. I now need to use this ID to query other data in another table. Is there any good way to make the query more efficient? Whether IN can be used or not, although it is easy to write with IN, the performance of IN is not good. I wonder if you have any good methods

Mar.06,2021

the simplest is a circular query, which is simple and convenient but inefficient, and if it is a project, it can affect performance. Another way is to segment the array and then combine to query the database. It would be better this way.


1, use exists instead of in
2, personId to create an index to improve query efficiency


IN is not the first choice, consider the efficiency first, it must be a linked table query, you look at the actual demand using join.


it is recommended that you do not use IN, to create a new table to save these personId, queries.

Menu