当前位置:网站首页>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 作为隐藏的聚集索引,
它会随着行记录的写入而主键递增。
边栏推荐
- Airserver mobile phone third-party screen projection computer software
- Basic knowledge of ngnix
- Go — 相关依赖对应的exe
- Sonic cloud real machine learning summary 6 - 1.4.1 server and agent deployment
- PCB plug hole technology~
- 13th Blue Bridge Cup group B national tournament
- 【MySQL】数据库优化方法
- CNN convolution neural network principle explanation + image recognition application (with source code) [easy to understand]
- The leader of the cloud native theme group of beacon Committee has a long way to go!
- [intelligent QBD risk assessment tool] Shanghai daoning brings you leanqbd introduction, trial and tutorial
猜你喜欢
Icml2022 | interventional contrastive learning based on meta semantic regularization
Basic operation of binary tree
BlocProvider 为什么感觉和 Provider 很相似?
pytest合集(2)— pytest運行方式
CIO's discussion and Analysis on the definition of high-performance it team
名单揭晓 | 2021年度中国杰出知识产权服务团队
Sonic云真机学习总结6 - 1.4.1服务端、agent端部署
详解LockSupport的使用
Business visualization - make your flowchart'run'up
AirServer2022最新版功能介绍及下载
随机推荐
Test cancellation 1
焱融看 | 混合云时代下,如何制定多云策略
Mask wearing detection method based on yolov5
Interview question: what is the difference between MySQL's Union all and union, and how many join methods MySQL has (Alibaba interview question) [easy to understand]
Manually implement function isinstanceof (child, parent)
Copy ‘XXXX‘ to effectively final temp variable
Simple interactive operation of electron learning (III)
Application of real estate management based on 3D GIS
名单揭晓 | 2021年度中国杰出知识产权服务团队
Design and practice of new generation cloud native database
地图其他篇总目录
对象内存布局
One of the basic learning of function
CSDN购买的课程从哪里可以进入
MIT|256KB 内存下的设备上训练
#yyds干货盘点# 解决名企真题:扭蛋机
Redis配置与优化
从MLPerf谈起:如何引领AI加速器的下一波浪潮
Microsoft, Columbia University | Godel: large scale pre training of goal oriented dialogue
TOPS,处理器运算能力单位、每秒钟可进行一万亿次