thinkphp MySQL two table query with in IDs or left join (the case, IDs array generally about 20)?

Source: Internet
Author: User
Not sure which solution is good
In the book to see that is generally a sub-table query, in favor of caching

Reply content:

Not sure which solution is good
In the book to see that is generally a sub-table query, in favor of caching

Mainly look at the data volume, as well as the application scenario, the amount of data is small, the two almost
Where in () query or multi-table left JOIN union query, which is more efficient?

You're talking about a SQL problem, using a left join that's far more than using in.

The two syntaxes use a different scenario, in which the ID is used to filter out records that match your ID group, and the left join is the associated table. If I do paging, see if the associated table is a large table (hundreds of thousands of millions of records), and then decide whether to use a left join, even if it is best to use the join explain to see if it is optimal, no, look at the results of explain optimization. It is recommended that you do not join the super-large table, in words, extract the ID and query table assembly data into the main table data set without multiple loops, the efficiency is not necessarily slow to go.

  • 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.