当前位置:网站首页>Mysql 45讲学习笔记(十)force index
Mysql 45讲学习笔记(十)force index
2022-07-04 06:33:00 【孔汤姆】
一.优化器的逻辑
选择索引是优化器的工作
优化器选择索引的目的:
- 找一个最优的执行方案,用最小的代价执行语句
- 执行行数是影响执行代价的因素之一。
- 扫描的行数越少,意味着访问磁盘数据的次数越少 ,消耗CPU资源越少。
优化器还会结合是否使用临时表,是否排序等因素。
二.扫描行数怎么判断
show index方法 查看索引基数
MySQL得到索引的基数
采样统计:
- 整张表取出来一行行统计,虽然可以得到精确的结果但是代价很高,只能选择“采样统计”
- InnoDB默认选择N个数据页,统计这些页面上的不同值,得到一个平均值,然后乘以这个索引的页面数,得到索引基数。
- 当变更的数据杭超过1/M的时候会自动触发一次索引统计。
innodb_stats_persistent
统计磁盘还是内存
- 设置on时候,统计持久化存储
- 设置off时候,统计内存中信息
analyze table t 可以用来统计索引信息
索引选择异常和处理
大多数时候优化器都能找到正确的索引,但是偶尔你还是会碰到上面情况:
- 采用 force index 强行选择一个索引
缺点:
- 程序员不喜欢使用force index,索引改完名字,这个语句就需要改。
优点:
- 使用force index最主要的问题还是变更的及时性。一般等待线上出现问题的时候,才会修改SQL语句,加上force index。但是修改之后还要测试和发布。对于生产系统来说,这个过程不够敏捷。
2.修改语句,引导 MySQL 使用我们期望的索引
3.可以新建一个更合适的索引,来提供给优化器做选择,或删掉误用的索引
边栏推荐
- FRP intranet penetration, reverse proxy
- Cloud native - SSH article that must be read on the cloud (commonly used for remote login to ECS)
- 颈椎、脚气
- 对List进行排序工具类,可以对字符串排序
- Error CVC complex type 2.4. a: Invalid content beginning with element 'base extension' was found. Should start with one of '{layoutlib}'.
- 2022 Xinjiang's latest eight members (Safety Officer) simulated examination questions and answers
- C语言中的排序,实现从小到大的数字排序法
- Common usage of time library
- Review | categories and mechanisms of action of covid-19 neutralizing antibodies and small molecule drugs
- How to use multithreading to export excel under massive data? Source code attached!
猜你喜欢

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

实用的小工具指令

云原生——上云必读之SSH篇(常用于远程登录云服务器)

2022 Xinjiang's latest eight members (Safety Officer) simulated examination questions and answers

Functions in C language (detailed explanation)

2022 where to find enterprise e-mail and which is the security of enterprise e-mail system?

Weekly summary (*63): about positive energy

How to avoid JVM memory leakage?
![[MySQL] introduction, function, creation, view, deletion and modification of database view (with exercises)](/img/03/2b37e63d0d482d5020b7421ac974cb.jpg)
[MySQL] introduction, function, creation, view, deletion and modification of database view (with exercises)

Another company raised the price of SAIC Roewe new energy products from March 1
随机推荐
How to avoid JVM memory leakage?
Invalid bound statement (not found): com. example. mapper. TblUserRecordMapper. login
[March 3, 2019] MAC starts redis
Common usage of time library
Stc8h development (XII): I2C drive AT24C08, at24c32 series EEPROM storage
C # symmetric encryption (AES encryption) ciphertext results generated each time, different ideas, code sharing
Software keywords and process information intercepted by Golden Shield video player
Data analysis notes 09
AWT介绍
11. Dimitt's law
Redis面试题集
STC8H开发(十二): I2C驱动AT24C08,AT24C32系列EEPROM存储
1、 Relevant theories and tools of network security penetration testing
QT 获取随机颜色值设置label背景色 代码
Invalid revision: 3.18.1-g262b901-dirty
Experience weekly report no. 102 (July 4, 2022)
Practical gadget instructions
ORICO ORICO outdoor power experience, lightweight and portable, the most convenient office charging station
Cloud native - SSH article that must be read on the cloud (commonly used for remote login to ECS)
JSON web token -- comparison between JWT and traditional session login authentication