Javascript-how to optimize the query time caused by a huge array of user IDs in the in statement of multi-table join query?

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.