mysql索引

索引操作

image-20220225113231934

image-20220225165058041

image-20220225165157522

image-20220225165542372

image-20220225144851126

索引简述

image-20220225172021518

索引分类

image-20220225172341387

mysql索引使用B+树不使用其他树的原因分析

B+树数据结构及其原理

具体图示原理可参照https://www.cs.usfca.edu/~galles/visualization/BPlusTree.html

B+树添加和删除数据图解

image-20220225172406287

存储引擎 :不同的存放位置,不同的存放格式

不同的存储引擎,数据文件和索引文件存放的位置是不同的,因此有了分类;

聚簇索引:数据和文件是放在一起的,innodb

​ .frm:存放的是表结构

​ .ibd:存放数据文件和索引文件

mysql的innodb存储引擎默认情况下会把所有的数据文件放到表空间中,不会为每一个单独的表保存一份数据文件,如果需要将每一个表单独使用文件保存,设置如下属性:set global innodb_file_per_table=on;

非聚簇索引:数据和索引单独一个文件:MyISAM

innodb:磁盘 MyISAM:磁盘 memory:内存

mysql索引系统

show tables;
-- pk主键  fk外键  unique唯一约束  这些约束自带索引

-- 建立索引
create table s1(
id int unsigned auto_increment,  -- 设置为无符号自增
name varchar(30),
score tinyint unsigned, -- 设置为无符号
primary key(id),
 key(name desc)  -- 设置为外键
);
describe s1;
drop table s1;
select * from s1;

create table s2(
id int UNSIGNED,
name varchar(30),
score tinyint unsigned,
index iname (name(30))
);
show index from s2;

create table s3(
id int unsigned,
name varchar(30),
score tinyint unsigned
);
show index from s3;

-- 建立索引
create index is3 on s3(name);
create index is33 on s3(id);

-- 建立唯一索引
create unique index is333 on s3(score);

-- 使用索引,查询语句使用where语句时使用的便有索引

-- 删除索引
drop index is3 on s3;



-- 查看表中所有索引
show index from s1;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值