Add several experience in mysql Performance Optimization

Source: Internet
Author: User
Added several experience in mysql performance optimization. use limit1 when only one piece of data is required. If you are sure that only one piece of data may exist under your condition, do not allow mysql to continue searching. Comparison example 1.1.select * fromtablenamewhereid1; 1.2.select1fromtablenamewhereid1limit1. if

Added several experience in mysql performance optimization. use limit 1 when only one piece of data is needed. If you are sure that you have a condition, only one piece of data may exist, please do not let mysql continue to search for the comparison case 1.1.select * from tablename where id = 1; 1.2.select 1 from tablename where id = 1 limit 1; 2. if

Added several experience in mysql Performance Optimization

1. Use limit 1 when only one piece of data is needed. If you are sure that there is only one piece of data under your conditions, please do not let mysql continue searching.

Comparison case

1.1.select * from tablename where id = 1;

1.2.select 1 from tablename where id = 1 limit 1;

2. If a field in the table is often used for query, use the index to mark the field.

Alter table tablename and index (fieldone );

In this way, the query efficiency will increase a lot.

3. When joining a table, use an equivalent type of column and index it.

If you use a large number of join queries in an SQL statement, check whether the condition fields in the two tables are indexed and the fields are of the same type. For example, use the following statement to perform the join link.

Select * from table1 t1 left join table2 t2 on t1.name = t2.name;

Make sure that t1.name and t2.name have the same character set and that the name has an index in both tables. Therefore, the query speed will be improved significantly.

4. Avoid using select *

If you are sure you want to obtain some columns in the table, use the following query:

Select field1 from table1?

Instead

Select * from table1

Because more queries will naturally increase the pressure on database queries. At the same time, when the data is transferred from the background to two independent servers at the front end, the network transmission pressure will also be increased, it is recommended that you use the required fields as much as possible to obtain the required fields.

5. we should set an auto-increment column for each table as the primary key, and the field type is unsigned (unsigned), and then auto_increment (automatically increasing ), do not use varchar fields as the primary key, even if they are unique.

?

We will summarize the above examples for the moment and continue later.

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.