Preface In the application of database, programmers have summed up a lot of experience through continuous practice. These experiences are some generally applicable rules. Every programmer should understand and remember them. When constructing SQL, develop good habits. Let's take a look at the detailed introduction without further ado: MySQL basic statement optimization principles 1. Avoid operations on columns as much as possible, as this will cause index failure select * from t where YEAR(d) >= 2011; Optimized for select * from t where d >='2011-0101' 2. When using JOIN, you should use a small result set to drive a large result set, and split complex JOIN queries into multiple queries, because JOINing multiple tables may cause more locking and blocking 3. When using LIKE, avoid using %% 4. Select the specified query field, do not check all of them, save memory 5. Use batch insert statements to save interactions 6. When the cardinality of limit is relatively large, use between. Between is faster than limit, but between also has its flaws. If there is a line break in the middle of the id or the middle part of the id is not read, the data will be less. select * from t where 1 limit 100000,10 Optimized for select * from t where id between 100000 and 100010 7. Do not use the rand function to fetch multiple random records 8. Avoid using NULL 9. Don’t use 10. Don’t do unnecessary sorting operations, but try to complete the sorting in the index as much as possible Summarize The above is the full content of this article. I hope that the content of this article can bring some help to your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support of 123WORDPRESS.COM. You may also be interested in:
|
<<: Linux kernel device driver system call notes
>>: A brief discussion on several ways to pass parameters in react routing
Nginx can use the limit_req_zone directive of the...
1. RPM version installation Check if there are ot...
In the past, creating a printer-friendly version ...
1. Environmental Description (1) CentOS-7-x86_64,...
Angular Cookie read and write operations, the cod...
The MySQL development team officially released th...
Mysql commonly used display commands 1. Display t...
Table of contents Preface: 1. Create index method...
1. Which three formats? They are: gif, jpg, and pn...
1. Package the Java project into a jar package He...
Table of contents Small but beautiful Keep it sim...
1. Nginx service foundation Nginx (engine x) is d...
Preface My needs are syntax highlighting, functio...
This article mainly introduces common strategies ...
Table of contents 1. Background 2. Local custom i...