当前位置:网站首页>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.可以新建一个更合适的索引,来提供给优化器做选择,或删掉误用的索引
边栏推荐
- Fundamentals of SQL database operation
- How does apscheduler set tasks not to be concurrent (that is, execute the next task after the first one)?
- Dimension and format of data
- C實現貪吃蛇小遊戲
- C实现贪吃蛇小游戏
- ES6 modularization
- 金盾视频播放器拦截的软件关键词和进程信息
- 报错cvc-complex-type.2.4.a: 发现了以元素 ‘base-extension‘ 开头的无效内容。应以 ‘{layoutlib}‘ 之一开头。
- Option (024) - do all objects have prototypes?
- Json Web token - jwt vs. Traditional session login Authentication
猜你喜欢

A little understanding of GSLB (global server load balance) technology

AWT introduction
![[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)

24 magicaccessorimpl can access the debugging of all methods

Detailed explanation of common APIs for component and container containers: frame, panel, scrollpane
![[backpack DP] backpack problem](/img/7e/1ead6fd0ab61806ce971e1612b4ed6.jpg)
[backpack DP] backpack problem

QT qtablewidget table column top requirements ideas and codes

buuctf-pwn write-ups (8)

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

Leetcode question brushing record | 206_ Reverse linked list
随机推荐
[number theory] fast power (Euler power)
剑指 Offer II 038. 每日温度
JSON Web Token----JWT和传统session登录认证对比
Fundamentals of SQL database operation
如何实现视频平台会员多账号登录
Vant --- detailed explanation and use of list component in vant
2022 wechat enterprise mailbox login entry introduction, how to open and register enterprise wechat enterprise mailbox?
QT releases multilingual International Translation
Option (024) - do all objects have prototypes?
MySQL installation and configuration
Layoutmanager layout manager: flowlayout, borderlayout, GridLayout, gridbaglayout, CardLayout, BoxLayout
Distributed cap theory
70000 words of detailed explanation of the whole process of pad openvino [CPU] - from environment configuration to model deployment
C实现贪吃蛇小游戏
lightroom 导入图片灰色/黑色矩形 多显示器
How to avoid JVM memory leakage?
Common JS tool Libraries
QT get random color value and set label background color code
Invalid revision: 3.18.1-g262b901-dirty
报错cvc-complex-type.2.4.a: 发现了以元素 ‘base-extension‘ 开头的无效内容。应以 ‘{layoutlib}‘ 之一开头。