How to optimize mysql multi-Table query + paging?

Source: Internet
Author: User
The question is not how to perform joint queries, but some people say that it is best not to use multi-table joint queries for large data volumes, therefore, it is optimal to know how to write an SQL statement to retrieve the paging data list from multiple tables. Supplement: Suppose there are two tables: Table A is the master table, and table B's data is the screening of Table... the question is not how to perform joint queries, but some people say that it is best not to use multi-table joint queries for large data volumes, therefore, it is optimal to know how to write an SQL statement to retrieve the paging data list from multiple tables.
Supplement: Assume that there are two tables: Table A is the master table and table B is one of the filtering conditions for querying Table.

Reply content:

The question is not how to perform joint queries, but some people say that it is best not to use multi-table joint queries for large data volumes, therefore, it is optimal to know how to write an SQL statement to retrieve the paging data list from multiple tables.
Supplement: Assume that there are two tables: Table A is the master table and table B is one of the filtering conditions for querying Table.

First, identify the ids of a table record, and then use in query for another table

There is no specific business scenario to talk about optimization.
Add the redundant fields of Table B in Table A. You can obtain one page of content directly by querying Table A. Other information of the associated table B can also be obtained directly, you can also obtain the data in the cache using the id of Table B.

Such optimization will increase maintenance costs, but the lower the paradigm level, the higher the query efficiency.

For reference only.

In some special business scenarios, joint queries are required. It cannot be blindly optimized.
Ids in queries. Tens of thousands of ids are obtained. It is better to directly join the query. Although this solution is good.

Optimization refers to optimization without affecting the business.

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

To optimize the query, We need to optimize the data structure first, and think about whether you have to use two tables, but not one row. You can also understand the built-in database functions, such as left (), right (), substring (), and substring_index (). There are also mid () and substr (). Do not move LIKE and so on, mainly write more, according to the actual application scenario to make the best judgment.

By the way, MYSQL configurations can also be optimized, such as query_cache.

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.