起因
为了测试explain, 也为了测试关于索引优化准备数据
- 新建了一张测试表
-
CREATE TABLE `tb_demo` ( `id` int NOT NULL AUTO_INCREMENT, `name` varchar(50) DEFAULT NULL, `score` decimal(10,1) DEFAULT NULL, `remark` varchar(50) DEFAULT NULL, `create_time` datetime DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
- 批量插入的存储过程
-
DROP PROCEDURE IF EXISTS `insertdata`; DELIMITER $$ CREATE PROCEDURE `insertdata`(IN record INTEGER) BEGIN DECLARE number INTEGER ; SET number=1; START TRANSACTION; WHILE number <=record DO INSERT INTO tb_demo (name, score, remark, create_time) VALUES(CONCAT('哈哈', number), number, '我测试', NOW()); SET number =number+1; END WHILE; COMMIT; END$$ DELIMITER ;
- 新建一条普通索引
-
-- 200w条数据 执行差不多8分钟 call `insertdata`(2000000);
测试
EXPLAIN select score from tb_demo where score > 200 and score < 500
为啥图中的 走了回表? 我理解只查询了索引 不会去找表里的其他数据啊???
接下来我又这么做了一下
EXPLAIN select * from tb_demo where score > 200 and score < 500
what??? 查询所有行 不回表了???
标签:DEFAULT,explain,疑似,insertdata,score,NULL,tb,bug From: https://www.cnblogs.com/liyong888/p/17254408.html