mysql info表,id 主键 自增长 数据20万左右
用order by id 特别慢
select id,title from info order by id desc limit 80100,50; |用时8秒select id from info order by id desc limit 80100,50; |用时0.05秒为什么差这么多呢? 能解释下吗如果我想title一起读出来怎么办呢。难道要分两次读才行吗。
用order by id 特别慢
select id,title from info order by id desc limit 80100,50; |用时8秒select id from info order by id desc limit 80100,50; |用时0.05秒为什么差这么多呢? 能解释下吗如果我想title一起读出来怎么办呢。难道要分两次读才行吗。
解决方案 »
- mysql 触发器 删除之后 在重新填入 数据 出错
- Lost connection to MySQL server during query
- mysql grant 授权不起作用
- postgresql备份
- 管理mysql的客户端工具
- 如果用VC编程的话,怎样在Mysql中存取二进制的数据?急!!!!!!!
- mysql中的数据能不能导入sqlserver2000中
- 求助:如何导入数据
- 请问一下,这段在VB中的代码错在哪里?
- ERROR 1045 (28000): Access denied for user 'root'@'localhost'[灌水免进 有分了可以补给]
- 查重,重复数据取其中一条
- 一对多查询
id,是id的吗?
而这个MYSQL仅通过访问索引文件就可以获得 ID,不需要再去访问数据文件。
+----+-------------+-------+------+---------------+------+---------+------+--------+----------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+--------+----------------+
| 1 | SIMPLE | info | ALL | NULL | NULL | NULL | NULL | 227903 | Using filesort |
+----+-------------+-------+------+---------------+------+---------+------+--------+----------------+
1 row in set (0.00 sec)
+----+-------------+-------+------+---------------+--------+---------+-------+--------+-----------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+--------+---------+-------+--------+-----------------------------+
| 1 | SIMPLE | info | ref | status | status | 1 | const | 198341 | Using where; Using filesort |
+----+-------------+-------+------+---------------+--------+---------+-------+--------+-----------------------------+
1 row in set (0.11 sec)
select id,title from info a
inner join
(select id from info order by id desc limit 80100,50) b
on a.id=b.id
这条语句,explain看是用到索引了。为什么执行SQL的时候还是很慢。也要10多秒!去掉 order by id desc,要快点,0。7秒。还是慢难道这种情况只能 先查出ID组,然用得到的ID组去多次取ID所在行的数据吗。
你要看到用到索引是status的索引而不是order by字段的索引,不一样,所以最后还是用到了filesort来排序,所以速度慢