MySQL 是关系型数据库.
- 什么是关系, 关系就是表..
- 数据库是什么. 数据库 即是 海量 数据
1. 实验用表
表结构
![](https://img.haomeiwen.com/i4740199/5a66bf89b0752cfc.png)
![](https://img.haomeiwen.com/i4740199/ab941c98f636c8e7.png)
2. 野生 limit
select * from messages limit 1000000,2;
![](https://img.haomeiwen.com/i4740199/858c8ba0a1cdc295.png)
![](https://img.haomeiwen.com/i4740199/ee3aae74868b2335.png)
type: const, eq_reg, ref, range, index, all
type: ALL 表示进行一次全表查询, 这个类型是最慢的
3. 优化limit 一
# 需要主键自增, 连续
select * from message where id >= 1000000 limit 10;
![](https://img.haomeiwen.com/i4740199/1e4f0a42090afd3e.png)
![](https://img.haomeiwen.com/i4740199/4b7eca752d71e16b.png)
4. 优化limit 二
这个语句比上一句又快了许多
select * from messages where id between 1000000 and 1000001;
![](https://img.haomeiwen.com/i4740199/70ba5dc865af65ff.png)
![](https://img.haomeiwen.com/i4740199/ed45eee2551e0afb.png)
网友评论