limit 的奇怪问题
语句 select * from T order by id desc 加了limit子句后,因limit offset差异而效率既然不同。
T的id字段为主键,以下是offset 为47和48时的explain结果,48时主键居然没有用上,这是为何?
mysql> explain select * from T order by id desc limit 47, 30; +----+-------------+--------+-------+---------------+---------+---------+------+------+-------+| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |+----+-------------+--------+-------+---------------+---------+---------+------+------+-------+| 1 | SIMPLE | T | index | NULL | PRIMARY | 4 | NULL | 77 | | +----+-------------+--------+-------+---------------+---------+---------+------+------+-------+1 row in set (0.00 sec)mysql> explain select * from T order by id desc limit 48, 30; +----+-------------+--------+------+---------------+------+---------+------+----------+----------------+| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |+----+-------------+--------+------+---------------+------+---------+------+----------+----------------+| 1 | SIMPLE | T | ALL | NULL | NULL | NULL | NULL | 44224755 | Using filesort | +----+-------------+--------+------+---------------+------+---------+------+----------+----------------+1 row in set (0.00 sec)