MySQL simple optimization "easy to learn"

Source: Internet
Author: User

1, select the most applicable field properties;

table field as small as possible, do not add unnecessary space to the database, such as: the value of ' 01 ', ' 02 ', to char (2) can be;

2, use the connection (join) to replace the subquery (sub-queries);

Using join IS because MySQL does not need to create a temporary table in memory to complete this logical two-step query effort.

3, the establishment index;

Generally used in join,where judgment, the order is ordered on the field.

4. Avoid using SELECT * from table name;

What fields you want to write.

5, try to avoid in where in! = or <>, or discard the use of the index for full table scanning;

6. try to avoid the null value of the field in the where, use or as the connection condition, otherwise it will cause the engine to abandon using the index for full table scan;

7, the following query will also result in a full table scan: (Can not be placed before and after the percent sign);

Select ID from the where name like '% sheet% '

8, in and not in also to use with caution, for the value, can use between do not use in;

9, avoid the expression of the field in the Where to operate, it will also cause the full table scan;

Error: Select ID from user where age/2=10

Correct: Select ID from user where age=10*2

10, as far as possible to set the number of fields, because the engine in the processing of queries and connections, character type will be compared, the digital type will only be compared once;

Well, MySQL's simple optimization is about here, like a little bit of attention ~

MySQL simple optimization "easy to learn"

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.