当前位置:网站首页>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.可以新建一个更合适的索引,来提供给优化器做选择,或删掉误用的索引
边栏推荐
- STC8H开发(十二): I2C驱动AT24C08,AT24C32系列EEPROM存储
- Software keywords and process information intercepted by Golden Shield video player
- [MySQL] introduction, function, creation, view, deletion and modification of database view (with exercises)
- Sleep quality today 78 points
- C language exercises (recursion)
- C réaliser des jeux de serpents gourmands
- Stc8h development (XII): I2C drive AT24C08, at24c32 series EEPROM storage
- Arcpy 利用updatelayer函数改变图层的符号系统
- ABCD four sequential execution methods, extended application
- AWT介绍
猜你喜欢
报错cvc-complex-type.2.4.a: 发现了以元素 ‘base-extension‘ 开头的无效内容。应以 ‘{layoutlib}‘ 之一开头。
Which water in the environment needs water quality monitoring
Functions in C language (detailed explanation)
Distributed cap theory
Layoutmanager layout manager: flowlayout, borderlayout, GridLayout, gridbaglayout, CardLayout, BoxLayout
Bicolor case
Can the out of sequence message complete TCP three handshakes
Learning multi-level structural information for small organ segmentation
uniapp 自定义环境变量
17-18. Dependency scope and life cycle plug-ins
随机推荐
QT 获取随机颜色值设置label背景色 代码
Json Web token - jwt vs. Traditional session login Authentication
【MySQL】数据库视图的介绍、作用、创建、查看、删除和修改(附练习题)
C语言中的函数(详解)
thread priority
[Android reverse] function interception (CPU cache mechanism | CPU cache mechanism causes function interception failure)
70000 words of detailed explanation of the whole process of pad openvino [CPU] - from environment configuration to model deployment
ABCD four sequential execution methods, extended application
How to realize multi account login of video platform members
[number theory] fast power (Euler power)
Another company raised the price of SAIC Roewe new energy products from March 1
Is the insurance annuity product worth buying? Is there a hole?
198. House raiding
Option (024) - do all objects have prototypes?
How to implement cross domain requests
SQL join, left join, right join usage
8. Factory method
AWT introduction
Error CVC complex type 2.4. a: Invalid content beginning with element 'base extension' was found. Should start with one of '{layoutlib}'.
what the fuck! If you can't grab it, write it yourself. Use code to realize a Bing Dwen Dwen. It's so beautiful ~!