当前位置:网站首页>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 作为隐藏的聚集索引,
它会随着行记录的写入而主键递增。
边栏推荐
- Internet of things RFID, etc
- 完全注解的ssm框架搭建
- Unity uses SQLite
- Qtreeview+qabstractitemmodel custom model: the third of a series of tutorials [easy to understand]
- [ecological partner] Kunpeng system engineer training
- PCB plug hole technology~
- plantuml介绍与使用
- Business visualization - make your flowchart'run'up
- Show member variables and methods in classes in idea
- Which securities company should we choose to open an account for flush stock? Is it safe to open an account with a mobile phone?
猜你喜欢

Pytest Collection (2) - mode de fonctionnement pytest

Is PMP certificate really useful?

Classify boost libraries by function

Flume interview questions

Little p weekly Vol.11

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

Spark interview questions

Go - exe corresponding to related dependency

对象内存布局

AirServer2022最新版功能介绍及下载
随机推荐
The difference between NiO and traditional IO
Flume interview questions
Sonic cloud real machine learning summary 6 - 1.4.1 server and agent deployment
JS how to get a list of elements in a collection object
Unity 使用Sqlite
locust 系列入门
IDA动态调试apk
【单体】流辰信息I-BPSv3服务器推荐配置
PCB plug hole technology~
MySQL learning notes - SQL optimization of optimization
都能看懂的LIS(最长上升子序列)问题[通俗易懂]
Test cancellation 1
Introduction à l'ingénierie logicielle (sixième édition) notes d'examen de Zhang haifan
【juc学习之路第9天】屏障衍生工具
GaussDB(DWS)主动预防排查
linux下清理系统缓存并释放内存
QT 使用FFmpeg4将argb的Qimage转换成YUV422P
Make a three digit number of all daffodils "recommended collection"
Relationship and difference between enterprise architecture and project management
月入1W+的自媒体达人都会用到的运营工具