栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

MySQL语句执行需要超过一分钟的时间

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

MySQL语句执行需要超过一分钟的时间

请注意,这并不是建议您过一会儿再使用MyISAM。我只用它来获取我的ID,最小,最大和计数。因此,请忽略引擎。

create table ratings(   id int auto_increment primary key,    thing int null)engine=MyISAM;insert ratings (thing) values (null),(null),(null),(null),(null),(null),(null),(null),(null);insert ratings (thing) select thing from ratings;insert ratings (thing) select thing from ratings;insert ratings (thing) select thing from ratings;insert ratings (thing) select thing from ratings;insert ratings (thing) select thing from ratings;insert ratings (thing) select thing from ratings;insert ratings (thing) select thing from ratings;insert ratings (thing) select thing from ratings;insert ratings (thing) select thing from ratings;insert ratings (thing) select thing from ratings;insert ratings (thing) select thing from ratings;insert ratings (thing) select thing from ratings;insert ratings (thing) select thing from ratings;insert ratings (thing) select thing from ratings;insert ratings (thing) select thing from ratings;insert ratings (thing) select thing from ratings;insert ratings (thing) select thing from ratings;insert ratings (thing) select thing from ratings;insert ratings (thing) select thing from ratings;

我现在有470万行

select count(*),min(id),max(id) from ratings;+----------+---------+---------+| count(*) | min(id) | max(id) |+----------+---------+---------+|  4718592 |       1 | 4718592 |+----------+---------+---------+select * from `ratings` order by id limit 499500, 500;-- 1 second on a dumpy laptop

explain select * from `ratings` order by id limit 499500, 500;+----+-------------+---------+------+---------------+------+---------+------+---------+----------------+| id | select_type | table   | type | possible_keys | key  | key_len | ref  | rows    | Extra          |+----+-------------+---------+------+---------------+------+---------+------+---------+----------------+|  1 | SIMPLE      | ratings | ALL  | NULL          | NULL | NULL    | NULL | 4718592 | Using filesort |+----+-------------+---------+------+---------------+------+---------+------+---------+----------------+

explain select * from `ratings` where id>=499501 limit 500;+----+-------------+---------+-------+---------------+---------+---------+------+---------+-----------------------+| id | select_type | table   | type  | possible_keys | key     | key_len | ref  | rows    | Extra      |+----+-------------+---------+-------+---------------+---------+---------+------+---------+-----------------------+|  1 | SIMPLE      | ratings | range | PRIMARY       | PRIMARY | 4       | NULL | 4198581 | Using index condition |+----+-------------+---------+-------+---------------+---------+---------+------+---------+-----------------------+

故事的寓意可能是使用where子句。

不能排除出现僵局的可能性。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/387972.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号