当前位置:网站首页>Mysql——》Innodb存储引擎的索引
Mysql——》Innodb存储引擎的索引
2022-07-01 21:45:00 【小仙。】
推荐链接:
总结——》【Java】
总结——》【Mysql】
总结——》【Spring】
总结——》【SpringBoot】
Mysql——》Innodb存储引擎的索引
一、文件
frm:表结构文件
ibd:数据即索引
Q:为什么说在 InnoDB 中索引即数据,数据即索引?
A:在 InnoDB 里面,它是以主键为索引来组织数据的存储的,所以索引文件和数据文件是同一个文
件,都在.ibd 文件里面。 在 InnoDB 的主键索引的叶子节点上,它直接存储了我们的数据。
Q:一张 InnoDB 的表可能有很多个多索引,数据肯定是只有一份的,那数据在哪个索引的叶子节点上呢?
A:存在聚集索引/聚簇索引上
二、聚集索引/聚簇索引/主键索引
如果一张表同时有主键索引和其它索引:
主键索引:就是聚集索引,决定数据行的物理存储顺序,叶子节点存储数据
其他索引:就是二级索引/辅助索引,叶子节点存储主键的值
定义:索引键值的逻辑顺序跟表数据行的物理存储顺序是一致的。
示例:字典的目录是按拼音排序的,内容也是按拼音排序的,按拼音排序的这种目录就叫聚集索引。
三、二级索引/辅助索引
当 我 们 用 name 索 引 查 询 一 条 记 录 , 它 会 在 二 级 索 引 的 叶 子 节 点 找 到name=bobo, 拿到主键值id=1,然后再到主键索引的叶子节点拿到数据。
从这个角度来说,因为主键索引比二级索引少扫描了一棵 B+Tree,它的速度相对会快一些。

四、如果表中没有主键或者没有索引,数据存储在哪里?
1、如果我们定义了主键(PRIMARY KEY),那么 InnoDB 会选择主键作为聚集索引。
2、如果没有显式定义主键,则 InnoDB 会选择第一个不包含有 NULL 值的唯一索引作为主键索
引。
3、如果也没有这样的唯一索引,则 InnoDB 会选择内置 6 字节长的 ROWID 作为隐藏的聚集索引,
它会随着行记录的写入而主键递增。
边栏推荐
- PHP reflective XSS, reflective XSS test and repair
- LIS (longest ascending subsequence) problem that can be understood [easy to understand]
- 100年仅6款产品获批,疫苗竞争背后的“佐剂”江湖
- 都能看懂的LIS(最长上升子序列)问题[通俗易懂]
- plantuml介绍与使用
- 名单揭晓 | 2021年度中国杰出知识产权服务团队
- 旁路由设置的正确方式
- EasyExcel 复杂数据导出
- Training on the device with MIT | 256Kb memory
- Burpsuite simple packet capturing tutorial [easy to understand]
猜你喜欢

One of the basic learning of function

CIO's discussion and Analysis on the definition of high-performance it team

In the past 100 years, only 6 products have been approved, which is the "adjuvant" behind the vaccine competition

Introduction à l'ingénierie logicielle (sixième édition) notes d'examen de Zhang haifan

按照功能对Boost库进行分类

从零开始学 MySQL —数据库和数据表操作

Significance and measures of security encryption of industrial control equipment

详解JMM

MIT|256KB 内存下的设备上训练

Yan Rong looks at how to formulate a multi cloud strategy in the era of hybrid cloud
随机推荐
多种智能指针
对象内存布局
选择在同花顺上炒股开户可以吗?安全吗?
Unity 使用Sqlite
100年仅6款产品获批,疫苗竞争背后的“佐剂”江湖
What is the difference between consonants and Initials? (difference between initials and consonants)
【juc学习之路第9天】屏障衍生工具
指标陷阱:IT领导者易犯的七个KPI错误
【MySQL】数据库优化方法
The difference between NiO and traditional IO
News classification based on LSTM model
按照功能对Boost库进行分类
Talking from mlperf: how to lead the next wave of AI accelerator
Mask wearing detection method based on yolov5
BlocProvider 为什么感觉和 Provider 很相似?
Why must digital transformation strategies include continuous testing?
二叉树的基本操作
Classify boost libraries by function
业务可视化-让你的流程图'Run'起来
Sonic云真机学习总结6 - 1.4.1服务端、agent端部署