Some optimization methods of MySQL

Source: Internet
Author: User

Optimization of 1.Max

If there is no index, Max needs to retrieve all the rows to produce the results, which can be optimized by indexing:

CREATE INDEX  on products (price); Index the price in the Products table

In this way, querying the maximum value of price can quickly produce results.

2. Optimization of sub-queries

The following sub-query:

SELECT  from WHERE inch (SELECT from vendors);

You can use the Join method to optimize:

SELECT  from INNER JOIN  on = vendors.prod_id;

However, if the vendors contains duplicate prod_id, the duplicate query results are returned. Therefore, the DISTINCT keyword needs to be added.

Optimization of 3.Limit

Avoid using limit 500, 5, and so on, because 505 rows will be queried. When the primary key (for example, ID) Order increases, you can sort by the primary key and limit it to id>500 and <=505, which will only query for the 5 rows you want.

4. Horizontal Split and vertical split

Horizontal splitting means that data is stored in a table that is divided into several structures of the same number of fields, thus improving the efficiency of finding. Vertical splitting is the splitting of several columns of a table to form a new table, avoiding too many columns in the table.

Some optimization methods of MySQL

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.