当前位置:网站首页>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 作为隐藏的聚集索引,
它会随着行记录的写入而主键递增。
边栏推荐
- “丝路正青春 风采看福建”在闽外籍青年短视频大赛火热征集作品中
- Significance and measures of security encryption of industrial control equipment
- Airserver mobile phone third-party screen projection computer software
- The correct way to set the bypass route
- 完全注解的ssm框架搭建
- Burpsuite simple packet capturing tutorial [easy to understand]
- Unity uses SQLite
- 首席信息官对高绩效IT团队定义的探讨和分析
- 【MySQL】数据库优化方法
- 辅音和声母的区别?(声母与辅音的区别)
猜你喜欢

Aidl basic use

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

【juc学习之路第9天】屏障衍生工具

Icml2022 | interventional contrastive learning based on meta semantic regularization

mysql 学习笔记-优化之SQL优化

上半年暂停考试要补考?包含监理工程师、建筑师等十项考试

List announced | outstanding intellectual property service team in China in 2021

Go — 相关依赖对应的exe

Talking from mlperf: how to lead the next wave of AI accelerator

locust 系列入门
随机推荐
Gaussdb (DWS) active prevention and troubleshooting
Pytest Collection (2) - mode de fonctionnement pytest
[live broadcast review] the first 8 live broadcasts of battle code Pioneer have come to a perfect end. Please look forward to the next one!
Introduction à l'ingénierie logicielle (sixième édition) notes d'examen de Zhang haifan
[ecological partner] Kunpeng system engineer training
Design and practice of new generation cloud native database
详解LockSupport的使用
100年仅6款产品获批,疫苗竞争背后的“佐剂”江湖
Classify boost libraries by function
Can you get a raise? Analysis on gold content of PMP certificate
Go — 相关依赖对应的exe
从零开始学 MySQL —数据库和数据表操作
旁路由设置的正确方式
K-means based user portrait clustering model
二叉树的基本操作
The correct way to set the bypass route
Can I choose to open an account for stock trading on flush? Is it safe?
地图其他篇总目录
Medium pen test questions: flip the string, such as ABCD, print out DCBA
MIT|256KB 内存下的设备上训练