执行计划:
执行计划字段,黄色部分为重点:
1、ID(重点)
2、select type(了解):simple、primary、subquery、Derived、union、union result
3、partitions:
4、type(重点)
5、possible keys:查询字段中涉及到的索引
6、key:实际使用的索引
7、key_len的计算:索引的长度,主要是为了帮助判断复合索引字段有无失效,对于单索引无意义
8、ref:忽略
9、rows:发送给客户端的行数,太大需关注
10、filtered
11:extra(重点)
---------------------------------------------建表和添加数据--------------------------------------------
1、创建表test
CREATE TABLE `test` (
`id` int(3) DEFAULT NULL,
`name` varchar(10) DEFAULT NULL,
`mobilephone` varchar(20) DEFAULT NULL,
`grade` varchar(5) DEFAULT NULL,
`class` varchar(20) DEFAULT NULL,
KEY `idx_grade` (`grade`),
KEY `idx_mobilephone` (`mobilephone`),
KEY `idx_id_name_class` (`id`,`name`,`class`)
);
2、给表中添加数据:若是几条也可以直接用insert into,批量数据可用用存储过程,若如下存储过程代码有报错情况,可参见我另一篇博文:https://blog.csdn.net/weixin_39772200/article/details/104164775
drop procedure if exists proc_test;
delimiter $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `proc_test`()
BEGIN
set @i = 1;
set @array_name="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
set @array_grade="one two three four five six";
set @count=CHAR_LENGTH(@array_grade)-CHAR_LENGTH(REPLACE(@array_grade,' ',''))+1;
set @telphone_array="180 181 182 183 186 189 191 152 138 134";
set @count_pre=CHAR_LENGTH(@telphone_array)-CHAR_LENGTH(REPLACE(@telphone_array,' ',''))+1;
while @i<10000 do
set @name=substring(@array_name,round(1+RAND()*45),7);
set @left_num=FLOOR(1+rand()*@count);
set @grade=SUBSTRING_INDEX(SUBSTRING_INDEX(@array_grade,' ',@left_num),' ',-1);
set @count_left= FLOOR