MySQL Code Development considerations----Developing high-performance SQL

Source: Internet
Author: User

Preface

A service or a program, consisting of program + data. In this piece of data, the IO in the computer is much slower than the CPU, in order to reduce IO and reduce CPU operation. We think of the index the first time, but why the index is more efficient, because it reduces IO and does not have to traverse the entire table when querying.

A little knowledge of MySQL,

1) When creating a table, if a non-null field is guaranteed in the business, it is recommended to explicitly not NULL because NULL is required for a special designation in MySQL. Using NOT NULL fields is more space-saving. It's also good for the next index build.

2) The Count (*) and COUNT (ID) IDs represent a field. In MySQL, COUNT (*) will count Null in, and COUNT (ID) will not. If the statistics field contains null, the results of this two statistic are different.

3) using a function on the left side of the SQL statement equals the query to make the index unusable in that field. such as the length (str) function.

4) Indexes are also required to be stored in physical space, and often additions and deletions of the table does not fit too many indexes, because the maintenance of the index will be time consuming. A table builds up to 15 indexes. The smaller the length of the index, the better the index is ordered. If the query Max () and the like with the index, even the table does not have to query, fast to fly.

5) Null in MySQL does not participate in the comparison operation, name <> ' millet ' results are not included in the Name=null case. In cases where the business cannot guarantee that a field is NULL, you need to pay attention to the null pit when writing the code. Ensure that the data obtained is right and full, then consider the query rate problem

MySQL Code Development considerations----Developing high-performance SQL

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.