当前位置:网站首页>MySQL-01. Summary of database optimization and explain field knowledge in work
MySQL-01. Summary of database optimization and explain field knowledge in work
2022-06-23 10:24:00 【cfcoolya】
Database optimization - topic of conversation
Why optimize ?
- The throughput bottleneck of the system often appears in the access speed of the database
- There are more and more data in the database , Processing time will slow down accordingly
- Optimization principle : Reduce resource use , Increase the reaction speed of the system
0.Redis cache
- For this kind of information that does not change frequently and has a large amount of data , Add it to the cache , Improve the access efficiency of the system
- Reducing database connections is an optimization tool , Some queries do not need to access the database , You can cache the server redis,elasticsearch Add cache , Reduce database connections .
1. Master slave copy , Read / write separation
- The program uses more databases and updates less , Consider using when there are many queries , Reduce database pressure , Improve performance .
- adopt MySQL Master slave copy ,curd go master The server , Inquiry slaver From the server , So it's reduced to just one MySQL Server pressure .
2. Database parameter configuration optimization
- For example, the default maximum number of connections is 100, Even if SQL No matter how well the statement is optimized , No matter how high the hardware configuration is , Request exceeds 100 Have to wait , This is the result of unreasonable configuration .
- https://cloud.tencent.com/developer/article/1582406
3. Optimize the design of database table structure
- Select a reasonable field data type ( The database will eventually be written to disk , The length of the field also affects the size of the disk I/O operation ). such as : The age of a person is indicated by an unsigned unsigned tinyint that will do , It is not necessary to use integer Length of data type ; User's mobile number 11 Bit length , It is not necessary to 255 Length .
- SQL Optimize , Use index
3.1 Indexes
3.1.1. In which case the index is used
- Frequent fields as query criteria
- Fields sorted in the query , Access speeds up
- The fields counted or grouped in the query
- The data column with foreign key must be indexed
3.1.2. Which case does not require indexing
- Frequently updated fields
- where Fields not used in conditions
- There are too few records
- Fields with duplicate data
4.MySQL Performance optimization artifact -Explain
4.1 brief introduction
MySQL Provides a Explain command , It's right select Statement analysis , And the output select Details of execution , For developers to optimize .
4.2explain Introduction to main formats
4.2.1 id
select Identifier , Query serial number , by sql The order in which statements are executed .
4.2.2 select_type
| select_type | meaning |
|---|---|
| simple | ordinary SELECT sentence ( barring UNION Operation or subquery operation ) |
| primary | Indicates that this query is the outermost query |
| union | UNION In operation , Inside the query SELECT |
| subquery | First in subquery select |
| dependent union | UNION In operation , Inside the query SELECT( The inner layer of the SELECT Sentence and outer SELECT Statement has dependencies ) |
| subquery | First in subquery select |
| union result | UNION Results of operation ,id The value is usually NULL |
4.2.3 type
Best to worst
| type value | meaning |
|---|---|
| const | It's found by index once , At most one matching row in a single table ,primary key perhaps unique index Search for |
| eq_ref | Uniqueness index , In a multi table connection, the connection column of the driven table has primary key perhaps unique index Search for |
| ref | And eq_ref similar , But not using primary key perhaps unique index, It's a normal index . It can also be on a single table non-unique Index search |
| range | Range query in single table index , Use the index to query out some row data in a single table .ref The column will become null. |
| index | Than all Better |
| all | Full table scan |
4.2.4 key
- possible_key Index list , Not necessarily used in practice
- key Actual index used
- key_len Maximum possible length of index field
4.2.5 rows
- According to table statistics and index selection , Roughly estimate the number of rows to read to find the required record
4.2.6 extra
Contains additional information that is not suitable for display in other columns but is important
- using filesort Access is not in the order of indexes in the table
- using temporary Increased the burden of the database , Temporary tables are used to store intermediate result sets , Apply to group by,distinct, or order by Columns for different tables .
- using index well , Override index used
边栏推荐
- Year end answer sheet! Tencent cloud intelligent comprehensive strength ranks first in China!
- Unity技术手册 - 生命周期内速度限制(Limit Velocity Over Lifetime)子模块和速度继承(Inherit Velocity)子模块
- NOI OJ 1.3 16:计算线段长度 C语言
- 同花顺推荐么?手机开户安全么?
- Tencent tangdaosheng: practice "science and technology for the good" and promote sustainable social value innovation
- [day 23] given an array of length N, insert element x into the position specified by the array | array insertion operation 4
- oracle中遇到的bug
- 解决audio自动播放无效问题
- Golang quick start (2)
- 2021-05-12 interface definition and Implementation
猜你喜欢

2021-05-07构造器

Personal blog system graduation project opening report

Is IPv6 faster than IPv4?

个人博客系统毕业设计开题报告

几款实用软件分享

用贪吃蛇小游戏表白(附源码)

Developer, you may have some misunderstandings about cloud computing

Gorm advanced query

Lying trough, the most amazing paper artifact!

Unity技术手册 - 生命周期LifetimebyEmitterSpeed-周期内颜色ColorOverLifetime-速度颜色ColorBySpeed
随机推荐
What is a good quick development framework like?
2021-04-27类和对象
Mathematical analysis_ Notes_ Chapter 2: real and plural numbers
Is there anyone who plans to open source an industrial "seckill" system architecture?
Bugs encountered in Oracle
2021-05-07 constructor
SQL writing problem to calculate the ring ratio of the current month and the previous month
大作业合集
Install using snap in opencloudos NET 6
SQL教程之SQL 中数据透视表的不同方法
2021-05-11 instanceof and type conversion
2021-05-11 static keyword
2021-04-16 recursion
R和RStudio下载安装详细步骤
NOI OJ 1.3 20:计算2的幂 C语言
Set up a QQ robot for ordering songs, and watch beautiful women
汇编语言中断及外部设备操作篇--06
NOI OJ 1.3 16:计算线段长度 C语言
漫画 | Code Review快把我逼疯了!
JVM简单入门-01