当前位置:网站首页>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
边栏推荐
- How to help others effectively
- Mysql 45讲学习笔记(十四)count(*)
- 分布式CAP理论
- Sort list tool class, which can sort strings
- 2022年,或许是未来10年经济最好的一年,2022年你毕业了吗?毕业后是怎么计划的?
- tars源码分析之8
- Considerations for testing a website
- 2022年,或許是未來10年經濟最好的一年,2022年你畢業了嗎?畢業後是怎麼計劃的?
- 期末周,我裂开
- 2022 wechat enterprise mailbox login entry introduction, how to open and register enterprise wechat enterprise mailbox?
猜你喜欢
Bicolor case
分布式CAP理论
4G wireless all network solar hydrological equipment power monitoring system bms110
Which water in the environment needs water quality monitoring
C language exercises (recursion)
Google Chrome Portable Google Chrome browser portable version official website download method
Learning multi-level structural information for small organ segmentation
[backpack DP] backpack problem
27-31. Dependency transitivity, principle
Uniapp custom environment variables
随机推荐
MySQL installation and configuration
Data analysis notes 09
[backpack DP] backpack problem
Variables d'environnement personnalisées uniapp
Reading notes of Clickhouse principle analysis and Application Practice (4)
Appium基础 — APPium安装(二)
颈椎、脚气
Abap:ooalv realizes the function of adding, deleting, modifying and checking
List of top ten professional skills required for data science work
图的底部问题
Modify TCP timestamp to optimize transmission performance
Code rant: from hard coding to configurable, rule engine, low code DSL complexity clock
微信小程序使用rich-text中图片宽度超出问题
Summary of leetcode BFS question brushing
P26-P34 third_ template
树形dp
InputStream/OutputStream(文件的输入输出)
Practical gadget instructions
Mysql 45讲学习笔记(十四)count(*)
双色球案例