MySQL's FIND_IN_SET function is notorious for not utilizing indices, resulting in inefficient queries. However, there are alternative approaches to achieve the desired indexing behavior when dealing with comma-separated lists.
The technique described in the provided answer suggests using a prepared statement with a parameter accepting a string in the form of a comma-separated list. By using the range type with a non-NULL key in the prepared statement, it ensures that indices will be employed when executing the IN clause.
For instance, the following query performs a range search with an index on the 'id' column:
explain select * from ratings where id in (2331425, 430364, 4557546, 2696638, 4510549, ...)
While this approach allows for efficient indexed queries, it is crucial to consider the following precautions:
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3