当前位置:网站首页>7.15 Day21---MySQL----Index
7.15 Day21---MySQL----Index
2022-08-04 05:35:00 【Which cookie are you?】
目录
Syntax for creating and dropping indexes:
NYSQLHow the index is designed:
索引:
索引的优缺点:
时间上
Indexes can greatly improve the speed of queries
At the expense of the speed of additions, deletions and changes,Because in order to ensure the orderliness of the index when adding, deleting and modifying,需要动态维护索引
空间方面:索引需要占物理空间.
索引的分类
主键索引:关键字primary key
唯一索引:关键字 unique
普通索引(非唯一):关键字 index
全文索引:关键字 fulltext
聚簇索引=主键索引=一级索引
非聚簇索引=(唯一索引,普通索引)=二级索引

Frm文件:表结构文件
Ibd文件:表数据文件
Create drop alter-操作frm文件
Insert update delete -操作ibd文件

Only the primary key index is called a clustered index,A non-primary key index is called a non-clustered index
Innodb不支持全文索引
创建删除索引的语法
Clustered indexes are native to the table,We create non-clustered indexes ourselves,如果表没有主键.Then he will select the hidden column by defaultrowid 来创建聚簇索引
Syntax for creating and dropping indexes:
(聚簇索引=The primary key index comes with the table,We create non-clustered indexes ourselves)
(如果表没有主键,Then the hidden column will be selectedrowid来创建聚簇索引)
创建
1.在create table建表的时候添加索引
2.在create tableAfter the table is created successfully,使用alter语句添加索引
ALTER TABLE 表名 ADD INDEX 索引名(字段名);
3.在create tableAfter the table is created successfully,使用create index语句添加索引
CREATE INDEX 索引名 ON 表名(字段名);
删除
1.使用alter语句删除索引
ALTER TABLE 表名 DROR INDEX 索引名;
2.使用drop语句删除索引
ORDR INDEX 索引名 ON 表名;
索引的数据结构:
MYSQLThe index supports two data structures
1.B+TREE B+树结构的索引(支持范围查询)
2.HASH The index of the hash structure(不支持范围查询)
Evolution of data structures:
二叉树:
问题:Unable to balance itself



平衡二叉树-AVL树:
Left-handed algorithm:When the depth of the right leaf node-The depth of the left leaf node>1的时候,触发左旋
右旋算法:When the depth of the left leaf node-The depth of the right leaf node>1的时候,触发右旋
目的:Maintain the balance of the tree
多路平衡二叉树-B树:
树的度数:The number of elements that can be stored in each node
One-way tree:度数=1
多路树:度数=n,n>1
data of the same size,One-way trees aretall skinny tree,Multiway trees areChunky tree
The advantage of multi-way trees over single-way trees is that更少的磁盘IO就可以找到数据

NYSQLHow the index is designed:
Each node of the tree is a disk block,MYSQL将表的ibdThe file is split into many disk blocks,The size of each disk block is uniform16KB,每次磁盘IORead a disk block of data,A disk block of data is also called a page of data
B+树和B-树的区别:
1个节点=1个磁盘块=16KB
假设一行数据data是200字节,主键id是8个字节,B树,A disk block is approximately stored8行数据,B+树,A disk block can probably be stored1000个主键id
B+树:
1.The bottommost leaf nodes form a singly linked list
2.Some elements are redundant
3.Only the bottommost leaf nodes store data,All nodes in the upper layer only store the primary keyid
B-树:
行数据dataStored with the primary key
走索引:二分查找
不走索引:全部扫描
说说索引:

边栏推荐
- Will the 2023 PMP exam use the new version of the textbook?Reply is here!
- Typora 使用保姆级教程 | 看这一篇就够了 | 历史版本已被禁用
- 【论文阅读笔记】无监督行人重识别中的采样策略
- SLSA 框架与软件供应链安全防护
- 力扣:343. 整数拆分
- MySql data recovery method personal summary
- BFC、IFC、GFC、FFC概念理解、布局规则、形成方法、用处浅析
- [One step in place] Jenkins installation, deployment, startup (complete tutorial)
- MySql数据恢复方法个人总结
- OpenSSF 安全计划:SBOM 将驱动软件供应链安全
猜你喜欢

Canal mysql data synchronization

一个对象引用的思考

符号表

腾讯136道高级岗面试题:多线程+算法+Redis+JVM

编程大杂烩(四)
![[Cocos 3.5.2]开启模型合批](/img/d9/9e8f71c9a26c8052b11291fe3ba7ac.png)
[Cocos 3.5.2]开启模型合批

8.03 Day34---BaseMapper query statement usage

4.3 Annotation-based declarative transactions and XML-based declarative transactions

Can 't connect to MySQL server on' localhost3306 '(10061) simple solutions

入坑软件测试的经验与建议
随机推荐
12、分页插件
C Expert Programming Chapter 4 The Shocking Fact: Arrays and pointers are not the same 4.1 Arrays are not pointers
动态规划总括
TensorRTx-YOLOv5工程解读(一)
3面头条,花7天整理了面试题和学习笔记,已正式入职半个月
7.18 Day23 - the markup language
字节最爱问的智力题,你会几道?
The 2022 PMP exam has been delayed, should we be happy or worried?
利用Jenkins实现Unity自动化构建
Dynamic programming of the division of numbers
OpenRefine开源数据清洗软件的GREL语言
谷粒商城-基础篇(项目简介&项目搭建)
擎朗智能全国研发创新中心落地光谷:去年曾获2亿美元融资
7.16 Day22---MYSQL(Dao模式封装JDBC)
Plus版SBOM:流水线物料清单PBOM
What are the steps for how to develop a mall system APP?
使用Loadrunner进行性能测试
编程大杂烩(四)
Uni-app 小程序 App 的广告变现之路:全屏视频广告
TensorRT例程解读之语义分割demo