MySQL multi-table query + paging How to achieve optimal?

Source: Internet
Author: User
The question is not how to federate a query, but to see that some people say that it is best not to use multi-table federated queries for large data volumes, so it is optimal to know how to write SQL from multiple tables to get paginated data lists.
Add: If there are two tables: A table is the main table, and the data in B table is one of the filter criteria for querying a table

Reply content:

The question is not how to federate a query, but to see that some people say that it is best not to use multi-table federated queries for large data volumes, so it is optimal to know how to write SQL from multiple tables to get paginated data lists.
Add: If there are two tables: A table is the main table, and the data in B table is one of the filter criteria for querying a table

First identify the IDs that are recorded in the table, and then use the in query in another table

No specific business scenarios to talk about optimization are bullying ah.
In a table to increase the redundancy of table B, directly on the A-table query can be taken to a page of content, and the associated B table of other information can be directly taken, or through the ID of B table can be taken in the cache.

This optimization increases maintenance costs, but the lower the paradigm level, the higher the query efficiency.

For reference only.

There are some special business scenarios where you have to use a federated query. Cannot simply blindly optimize.
IDs in query, if IDs is out of tens of thousands of. It might as well be a direct union query. Although this plan is very good.

Optimization refers to the premise of not affecting the business, if only for optimization and optimization of the ╮(╯▽╰)╭

Pagination can refer to http://segmentfault.com/q/10100000001 ...

As for the optimization query, in essence, the first to optimize the data structure, think about whether you have to use two of tables, a row can not. And how much you know about the database built-in functions, such as Left (), right (), substring (), Substring_index (). There is also mid (), substr (). Do not be like and so on, mainly or write more, according to the actual application of the scene to make the best judgment.

By the way, the MySQL configuration itself can be a lot of optimizations, such as Query_cache and so on

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