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.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e39073-4451a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e39073-4451a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?