当前位置:网站首页>MySQL数据库索引
MySQL数据库索引
2022-07-23 21:16:00 【InfoQ】
MySQL有哪些情况不走索引?
- 索引列参与计算;
- 索引列使用了函数;
- 匹配值使用了前百分号;
- 字符串和数字比较;
- 没有遵循联合索引的最左前缀原则;
- 引擎认为全表扫描比使用索引的代价更低
索引的三种数据模型
- 哈希表:哈希表这种结构适用于只有等值查询的场景 MemCached 等NoSQL引擎
- 有序数组:有序数组在等值查询和范围查询场景中的性能就都非常优秀。使用二叉树的原理。时间复杂度是O logN;但是对于更新来说,效率比较底,所以有序数组索引只适用于静态存储引擎。
- 搜索树:二叉树->平衡二叉树->平衡N叉树
关于B+Tree
- 主键索引 叶子节点存储的是整行数据,InnoDB中,主键索引也称聚簇索引(Clustered Index)
- 非主键索引 叶子节点存储的是主键的值。InnoDB中,非主键索引也称二级索引(Seconday Index)
- 所有的叶子结点使用链表相连,便于区间查找和遍历。B树则需要进行每一层的递归遍历。相邻的元素可能在内存中不相邻,所以缓存命中性没有B+树好。
- b+树的中间节点不保存数据,能容纳更多节点元素。
索引示例
create table T(
id int primary key,
k int not null,
name varchar(16),
index (k))engine=InnoDB;
总结
边栏推荐
- WinDbg practice -- Introduction
- (Note)优化器Adam的学习率设置
- 1062 Talent and Virtue
- 支付宝常用接口统一封装,可直接支付参数使用(适用于H5、PC、APP)
- Pay more attention to which securities company has the lowest commission? Is it safe to open an account online?
- Microservice architecture vs single service architecture [what can Huawei cloud service do in the microservice mode]
- Chapter 3 business function development (creating clues)
- Jetson nano recording stepping on the pit (it will definitely solve your problem)
- 1062 Talent and Virtue
- 模块化开发
猜你喜欢
随机推荐
如何在面试中介绍自己的项目经验
Major optimization of openim - Message loading on demand, consistent cache, uniapp Publishing
Jianzhi offer II 115. reconstruction sequence: topological sorting construction problem
高数下|二重积分的计算3|高数叔|手写笔记
Junior intern, ByteDance, after sharing, has been offered
ES6特性:Promise(自定义封装)
1309_ Add GPIO flip on STM32F103 and schedule test with FreeRTOS
Chapter 2 Regression
How to introduce your project experience in the interview
SQLite database
第三届SLAM技术论坛-吴毅红教授
Detailed explanation of MSTP protocol for layer 3 switch configuration [Huawei ENSP experiment]
[leetcode] day101 rotating image
High numbers | calculation of triple integral 2 | high numbers | handwritten notes
Green-Tao 定理的证明 (2): Von Neumann 定理的推广
如何在面試中介紹自己的項目經驗
Scala programming (intermediate advanced experimental application)
vite3学习记录
MySql的DDL和DML和DQL的基本语法
LeetCode_376_摆动序列









