当前位置:网站首页>MySQL数据库索引教程(超详细)
MySQL数据库索引教程(超详细)
2022-07-05 18:33:00 【InfoQ】
索引初步
缺点
索引结构

实验准备(以下实验都在VMware中进行)
1、新建一个数据库
create database test default character set utf8;
2、新建一个数据表
CREATE TABLE testsql (
id int NOT NULL AUTO_INCREMENT PRIMARY KEY comment '自增主键',
dept tinyint not null comment '部门id',
name varchar(30) comment '用户名称',
create_time datetime not null comment '注册时间',
last_login_time datetime comment '最后登录时间'
) comment '测试表';
3、写入数据
insert into testsql values(1,1,'user_1', '2018-01-01 00:00:00', '2018-03-01 12:00:00');
4、赋值
set @i=1;
5、做一个表的倍数增加(不然几千万的数据写一年都写不完)
insert into testsql(dept, name, create_time, last_login_time)
select left(rand()*10,1) as dept, #随机生成1~10的整数
concat('user_',@i:[email protected]+1), #按序列生成不同的name
date_add(create_time,interval [email protected]*cast(rand()*100 as signed) SECOND), #生成有时间大顺序随机注册时间
date_add(date_add(create_time,interval [email protected]*cast(rand()*100 as signed) SECOND), interval + cast(rand()*1000000 as signed) SECOND) #生成有时间大顺序的随机的最后登录时间
from testsql;
6、查看
select count(*) from testsql;
show variables like "%_buffer%";
7、实验
select COUNT(*) from t where name='user_500000';
8、创建索引




9、实验效果
select COUNT(*) from t where name='user_500000';
边栏推荐
猜你喜欢

About Estimation with Cross-Validation

The main thread anr exception is caused by too many binder development threads

buuctf-pwn write-ups (9)

案例分享|金融业数据运营运维一体化建设

The worse the AI performance, the higher the bonus? Doctor of New York University offered a reward for the task of making the big model perform poorly

技术分享 | 接口测试价值与体系

AI Open2022|基于异质信息网络的推荐系统综述:概念,方法,应用与资源

彻底理解为什么网络 I/O 会被阻塞?

Case sharing | integrated construction of data operation and maintenance in the financial industry

A2L file parsing based on CAN bus (3)
随机推荐
How to obtain the coordinates of the aircraft passing through both ends of the radar
c语言简便实现链表增删改查「建议收藏」
Common time complexity
瞅一瞅JUC提供的限流工具Semaphore
jdbc读大量数据导致内存溢出
Is it safe for golden sun to open an account? Can I open an account free of 5 in case?
ICML2022 | 长尾识别中分布外检测的部分和非对称对比学习
常见时间复杂度
Introduction to the development function of Hanlin Youshang system of Hansheng Youpin app
蚂蚁集团开源可信隐私计算框架「隐语」:开放、通用
Problems encountered in the project u-parse component rendering problems
Tupu software digital twin | visual management system based on BIM Technology
sample_rate(采样率),sample(采样),duration(时长)是什么关系
LeetCode 6109. Number of people who know the secret
Memory leak of viewpager + recyclerview
[QNX Hypervisor 2.2用户手册]6.3.2 配置VM
Record eval() and no in pytoch_ grad()
C final review
websocket 工具的使用
Use QT to traverse JSON documents and search sub objects