当前位置:网站首页>Index invalidation caused by inaccurate MySQL statistics
Index invalidation caused by inaccurate MySQL statistics
2022-06-13 07:36:00 【Fish is not fish】
1. The impact of inaccurate statistical information
Inaccurate statistical information generally leads to MySQL The optimizer cannot select the correct index , Which leads to The optimizer selects the wrong index
Or do not go to the index , cause Index failure
, Leading to a large number of The slow query
.
2. Under what circumstances will the statistical information be inaccurate ?
Generally speaking , It can be divided into the following two cases :
The statistical information is not updated in time , Incorrect statistics invalidate the index .
Too many fragments in the table , Lead to Cardinality inaccurate , Calculation error .
Let's talk about two scenarios in detail :
The statistical information is not updated in time
Before this topic, let's look at some parameters :FOR MySQL 5.7:
In general, statistics are controlled by the following parameters :innodb_stats_persistent:
Controls whether statistics are persisted , The default .innodb_stats_auto_recalc:
Controls how many rows in the table are automatically updated after modification , The default is 10%, The default .innodb_stats_persistent_sample_pages:
The number of pages sampled during index statistics after statistics persistence is enabled , Default 20 A page , Too long sampling time will affect performance .innodb_stats_method:
Statistics encountered NULL How values are handled , Default NULL Equal value means nulls_equal.
In addition, you can see the details of statistical information in two tables :mysql.innodb_index_stats
and mysql.innodb_table_stats
These two tables will store some details , The table structure is as follows :
From the information of the two tables, you can see the last time of the statistical information .
Therefore, from the meaning of the parameters, we can see that there will be problems in the statistical information due to the untimely update of the statistical information .For MySQL 8.0:
Out of the above parameters , Introduce a new parameter :information_schema_stats_expiry:
Time of statistics in cache , The default is 86400s 1 God .
Too many table fragments
First look at a picture :Cardinality:
How many different values are counted in the table , The higher the value, the higher the index discrimination .
stay MySQL among , Index is data , But if there are too many fragments in the table , that Cardinality The statistics of values will be affected ,
For example, half of the table data is fragmented , So the marked positions are NULL That is, they all have the same value , Lead to
Cardinality Smaller value , Affect the optimizer to select the correct index .
3. How to solve the problem of inaccurate statistical information ?
Generally speaking, we can implement all three operations :
Analyse table
optimize table
alter table T engine=innodb
The above three methods can regenerate statistics . The difference is that
The first is only for statistical information .
The second and third will not only rearrange the statistical information , And the table will be rebuilt , Recycle the fragments in the table .
Refer to the website : https://www.modb.pro/db/77939
边栏推荐
- MySQL query timeout control
- Problems encountered during commissioning of C # project
- 10. process communication
- Upgrade the project of log4j to log4j2
- Nodejs file module FS
- Simple understanding of basic language of C language
- 【ViveFocus使用WaveVR插件获取手柄操作事件】
- Redis underlying data structure ----quicklist
- FTP_ Manipulate remote files
- Index push down (ICP) for mysql5.6
猜你喜欢
Consistency under distributed
First graphical interface
C#合并多个richtextbox内容时始终存在换行符的解决方法
Logback log framework learning and problems
Mui mixed development - when updating the download app, the system status bar displays the download progress
powerdisgner逆向生成oracle数据模型
redis-0. Introduction to redis and NiO principle (random talk)
Three handshakes and four waves of TCP protocol and why------ One two pandas
The password does not take effect after redis is set
Upgrade the project of log4j to log4j2
随机推荐
Local file upload FTP or remote directory
A. Vacations (dp 贪心
Distributed database tidb
11.29 Li Kou swipes questions every day
Time field comparison time size in MySQL
Ticdc introduction
论文笔记: 多标签学习 BP-MLL
MySQL does not recommend setting the column default value to null. Why on earth is this
【硬记】脏读、不可重复读、幻读场景核心区别
TCP协议的三次握手过程和四次挥手过程以及为什么要这样? ------一二熊猫
. Net code to implement get request and post request
关于c#委托、事件相关问题
FTP_ Manipulate remote files
Adding certificates to different systems
About database: pgadmin4 editing SQL window
Database outline
Redis cluster parsing docker building redis cluster
Compilation and development process of Quanzhi v3s environment
Fundamentals of assembly language: register and addressing mode
部署RDS服务