当前位置:网站首页>[MySQL performance optimization] - optimize query
[MySQL performance optimization] - optimize query
2022-06-21 08:12:00 【_ Superdream】
Preface
Optimize MySQL Database is a necessary skill for database administrator , Through different Optimization method To improve MySQL The purpose of database performance .
MySQL Database when the number of users and data is very small , It is difficult for us to judge MySQL Database performance . Only when the number of users and the amount of data increase ,MySQL How can the performance of . Inquire about Is the most frequent database operation , Improve Query speed Can effectively improve MySQL Database performance .

Optimized query
SHOW STATUS Statement query MySQL Database performance
The impact of index on query speed
SHOW STATUS Statement query MySQL Database performance
We can use SHOW STATUS Statement query MySQL Database performance .
Grammar format :
SHOW STATUS LIKE 'VALUE'VALUE The parameters are as follows
- Connection: Connect MySQL The number of servers .
- Uptime:MySQL The online time of the server .
- Slow_queries: Slow query times .
- Com_select: Number of query operations .
- Com_insert: The number of insert operations .
- Com_delete: The number of delete operations .
! Through these parameters, we can analyze MySQL Database performance . Then according to the analysis results , Conduct Corresponding performance optimization .
Analyze query statements
have access to EXPLAIN Statement and DESCRIBE Statement to analyze the query statement .
Grammar format :
#EXPLAIN Grammar format EXPLAIN SELECT sentence ; #DESCRIBE Grammar format DESCRIBE SELECT sentence ;Next, we're going to talk about EXPLAIN and DESCRIBE To introduce
Use EXPLAIN Statement analysis query statement
The meaning of each field :
id: Indicates that throughout the query select The location of .
table: Store the table name queried .
type: Connection type , Many values are stored in this column , Range from const To All.
possible_keys: Point out that in order to improve the search speed , stay MySQL Indexes that can be used in .
key: Indicate the keys actually used .
rows: Pointed out that MySQL You need to return the number of rows verified by the query result in the corresponding table , To get the total number of rows ,MySQL The entire query must be scanned , Multiply by the row value of each table .
Extra: Contains some additional information , Design MySQL How to handle queries .
Use DESCRIBE Statement analysis query statement
DESCRIBE The use of statements is the same as EXPLAIN The grammar is the same , The results of these two analyses are also roughly the same .
The impact of index on query speed
We use the index in the query process , It can improve the efficiency of database query , Reduce the number of queries . Next, let's use an example to compare the difference in query speed between using an index and not using an index .
We're looking through student Table to analyze the use and non use of indexes .
Queries without index
explain select * from student where stuname = 'zhangsan';
branch Analysis : Without using an index , We found that in the original table Three pieces of data They were all checked . And then someone will say , What is the impact of only three pieces of data ? Of course , When the amount of data is small , Query efficiency won't make much difference . If there is a large amount of data in the database , Like tens of millions of them , When we query, these tens of millions of data will be retrieved , Users traverse tens of millions of pieces of data in order to query one piece of data , It will consume a lot of time and resources .
Query using index
Let's give it first stuname Field plus index
CREATE INDEX index_stuname ON student(stuname);After adding the index, we are querying
explain select * from student where stuname = 'zhangsan';
branch Analysis : It can be seen from the above results that , The number of rows accessed due to the index created is determined by 3 Reduced to 1, therefore , In the query operation , Using indexes will not only Optimize query efficiency , Will Reduce server overhead .
LIKE Optimize index queries
When the first character is “%” when , Index will not be used , If “%” The position in the matching string is not the first position , Then the index will be Normal use .
explain select * from student where stuname like 'zh%';
Use multi column index
Multi column index creates an index on multiple fields of a table , Only when one of these fields is used in the query criteria , The index will be used normally .
Create multi column indexes
CREATE INDEX index_student ON student(stuname,stuage);Be careful : When we query, if we apply stuage Field , The index cannot be used normally , You have to use First field stuname when , The index takes effect normally . This must be remembered !
Use keywords or
! stay MySQL in , Query statements only contain keywords or when , It is required that the two fields of the query must Same as index , If the search criteria , One field is not indexed , The index will not be applied to the query , Indexes Will not enter into force , Query efficiency will not be improved .
If this article is helpful to my friends , I hope you can give me some praise and support ~ Thank you very much. ~

边栏推荐
- How to write attractive titles for short videos? Learn these tips to make your title more convincing
- Global and Chinese market for packed gas chromatographic columns 2022-2028: Research Report on technology, participants, trends, market size and share
- showCTF Web入门题系列
- How can we make millions a year now?
- 2021-07-28 STM32F103 configuration information
- Ansa secondary development - external programs use socket to communicate with ansa
- unity裏現實攝像頭運鏡並LookAt到物體前方 基於Dotween
- Cluster hui dsm7 add suite source
- (对于换行符)gets和fgets的区别,puts和fputs的区别
- Yunkang group passed the hearing: the revenue exceeded 1billion in 8 months and the profit within the period was 270Million
猜你喜欢

antd table长表格如何出现滚动条

MMS for risc-v

线上GO服务出现GC故障,我当时就急了

图解 Google V8 # 15:隐藏类:如何在内存中快速查找对象属性?

The market value of Jinshan office fell below 100 billion yuan: the shareholder Qiwen n-dimensional cash out exceeded 1.2 billion yuan

2022-2028 global internal gear motor industry research and trend analysis report
![[UML modeling] (4) sequence diagram of UML modeling](/img/e6/0fd15bca49e7894ce039d97f3798c3.jpg)
[UML modeling] (4) sequence diagram of UML modeling

为什呢代码没报错但是数据库里边的数据显示不出来

Le Code est correct, mais les données de la base de données ne sont pas affichées.

JVM内存模型概念
随机推荐
The market value of Jinshan office fell below 100 billion yuan: the shareholder Qiwen n-dimensional cash out exceeded 1.2 billion yuan
JVM memory model concepts
2021-07-28 STM32F103 I2C Hardware Transfer Include previous IO Clock EXIT USB use firmware library
[putty] a free SSH and telnet client
Difference between function declaration and function expression
Global and Chinese market for packed gas chromatographic columns 2022-2028: Research Report on technology, participants, trends, market size and share
Three ways to solve cross domain problems
2022-2028 global boom cylinder industry research and trend analysis report
2021-07-28 STM32F103 I2C Hardware Transfer Include previous IO Clock EXIT USB use firmware library
Is the index of nine interview sites of ten companies invalid?
showCTF 入门文件包含系列
How can we make millions a year now?
PHP类与对象详细介绍
Learning Tai Chi maker esp8226 (IX) JSON data communication III
You can't use typescript generics after reading it. Come to me for yyds dry inventory
一元多项式的乘法与加法运算 (20 分)
Practical application cases of digital Twins - coal mine
Solve the problem that Jenkins cannot save the configuration after upgrading
1004 Counting Leaves (30 分)
[yuanuniverse 3D competition]





