当前位置:网站首页>MySQL 45 lecture learning notes (x) force index
MySQL 45 lecture learning notes (x) force index
2022-07-04 06:38:00 【Tom Kong】
One . Optimizer logic
Choose the index yes The job of the optimizer
The purpose of the optimizer's index selection :
- Find an optimal implementation plan , Execute the statement with the least cost
- The number of execution lines is one of the factors that affect the execution cost .
- The fewer lines to scan , It means that the fewer times you access disk data , Consume CPU The less resources .
The optimizer also combines Whether to use temporary table , Is it sorted? Other factors .
Two . How to judge the number of scanning lines
show index Method View index cardinality
MySQL Get the cardinality of the index
Sampling statistics :
- Take out the whole table and make statistics row by row , Although accurate results can be obtained, the cost is very high , Can only choose “ Sampling statistics ”
- InnoDB Default choice N Data pages , Count the different values on these pages , Get an average of , Then multiply by the number of pages in this index , Get index base .
- When the changed data exceeds 1/M It will automatically trigger an index statistics .
innodb_stats_persistent
Count disk or memory
- Set up on When , Statistics persistent storage
- Set up off When , Statistics of information in memory
analyze table t It can be used to count index information
Index selection exceptions and handling
Most of the time, the optimizer can find the correct index , But occasionally you will encounter the above situation :
- use force index Force an index
shortcoming :
- Programmers don't like to use force index, Index name changed , This statement needs to be changed .
advantage :
- Use force index The main problem is the timeliness of changes . Generally, when there is a problem online , Will modify SQL sentence , add force index. But after modification, it has to be tested and released . For production systems , This process is not agile enough .
2. Modify the statement , guide MySQL Use the index we expect
3. You can create a more suitable index , To provide the optimizer with choices , Or delete the misused index
边栏推荐
- 《ClickHouse原理解析与应用实践》读书笔记(4)
- 24 magicaccessorimpl can access the debugging of all methods
- STM32 单片机ADC 电压计算
- What is the "relative dilemma" in cognitive fallacy?
- Tar source code analysis Part 2
- [MySQL] introduction, function, creation, view, deletion and modification of database view (with exercises)
- Variables d'environnement personnalisées uniapp
- Mysql 45讲学习笔记(十四)count(*)
- List of top ten professional skills required for data science work
- Mysql 45讲学习笔记(六)全局锁
猜你喜欢

《ClickHouse原理解析与应用实践》读书笔记(4)

Mysql 45讲学习笔记(七)行锁

uniapp 自定义环境变量

P26-P34 third_ template

QT get random color value and set label background color code

Bicolor case

746. Climb stairs with minimum cost

R statistical mapping - random forest classification analysis and species abundance difference test combination diagram

4G wireless all network solar hydrological equipment power monitoring system bms110

C language exercises (recursion)
随机推荐
Mysql 45讲学习笔记(十二)MySQL会“抖”一下
Tar source code analysis 9
2022年,或許是未來10年經濟最好的一年,2022年你畢業了嗎?畢業後是怎麼計劃的?
Another company raised the price of SAIC Roewe new energy products from March 1
Vant --- detailed explanation and use of list component in vant
【问题记录】03 连接MySQL数据库提示:1040 Too many connections
Tar source code analysis 8
[March 3, 2019] MAC starts redis
分布式CAP理论
C language - Blue Bridge Cup - Snake filling
STC8H开发(十二): I2C驱动AT24C08,AT24C32系列EEPROM存储
Mysql 45讲学习笔记(十一)字符串字段怎么加索引
Realize IIC data / instruction interaction with micro batg135
Appium基础 — APPium安装(二)
C realize Snake games
2022 wechat enterprise mailbox login entry introduction, how to open and register enterprise wechat enterprise mailbox?
Considerations for testing a website
R统计绘图-随机森林分类分析及物种丰度差异检验组合图
CORS is not intended to protect API endpoints - nikofischer
图的底部问题