mysql 一分钟内_MySQL语句需要超过一分钟才能执行

Drew..

15

请注意,这并不是建议使用MyISAM一分钟.我只是用它来得到我的id,min,max和count来排队.所以请忽略引擎.

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;

我现在有4.7M行

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子句.

人们不能排除陷入僵局的可能性.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值