In summary:
When designing a table:
index:
Summary: Use the appropriate data type and choose the appropriate index The writing of sql needs to be optimized: Use limit to limit the records in the query results Avoid select * and list the fields you need to search for. Use joins instead of subqueries Split large delete or insert statements You can find out the slow SQL by turning on the slow query log No column operations: SELECT id WHERE age + 1 = 10. Any operation on the column will result in a table scan, including database tutorial functions, calculation expressions, etc. When querying, try to move the operation to the right of the equal sign. The SQL statement should be as simple as possible: one SQL statement can only be executed on one CPU; large statements should be split into small statements to reduce the lock time; one large SQL statement can block the entire database Rewrite OR to IN: OR has an efficiency of n, while IN has an efficiency of log(n). The number of INs is recommended to be controlled within 200. No functions or triggers are needed to implement Avoid %xxx-style queries Use JOIN sparingly Use the same type for comparison, such as '123' and '123', 123 and 123 Try to avoid using the != or <> operators in the WHERE clause, otherwise the engine will abandon the index and perform a full table scan. For consecutive values, use BETWEEN instead of IN: SELECT id FROM t WHERE num BETWEEN 1 AND 5 Don't use the entire table for list data. Use LIMIT to split the data into pages. The number of pages should not be too large. engine: MyISAM Row locks are not supported. All tables that need to be read are locked when reading, and exclusive locks are added to the tables when writing. No support for transactions Foreign keys are not supported Does not support safe recovery after a crash Support inserting new records into the table while the table is being read and queried Supports indexing of the first 500 characters of BLOB and TEXT, and full-text indexing Supports delayed update of indexes, greatly improving write performance For tables that will not be modified, compression is supported to greatly reduce disk space usage InnoDB Support row locks and use MVCC to support high concurrency Support Affairs Support foreign keys Supports safe recovery after crash No full-text indexing support In general, MyISAM is suitable for SELECT-intensive tables, while InnoDB is suitable for INSERT- and UPDATE-intensive tables. Partition, table, and database (read-write separation) The above is a detailed explanation and integration of MySQL optimization strategies introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! You may also be interested in:
|
<<: Detailed explanation of Nginx rewrite jump application scenarios
>>: Vue+express+Socket realizes chat function
Each web page has an address, identified by a URL...
Table of contents 1. Install the psutil package S...
Network security is a very important topic, and t...
Table of contents think 1. Greedy Snake Effect Pi...
Use div to create a mask or simulate a pop-up wind...
Table of contents 1. Enter the network card confi...
Table of contents 1. How to create an array in Ja...
1. Command Introduction The userdel (user delete)...
1. Problem During development, when inserting dat...
Table of contents Preface 1. The significance of ...
Table of contents Function call optimization Func...
1. Performance schema: Introduction In MySQL 5.7,...
Ellipses appear when multi-line text overflows Th...
Icon icon processing solution The goal of this re...
Result: Implementation code: Need to be used with...