按主键限制选择(在有索引的列中)顺序1000看超过1000行

时间:2018-09-08 20:22:52

标签: mysql

此表有几百万行,子标识1有50,000。我想找到子ID 1的1000条最新行,并且说明显示搜索到99000行。为什么我没有索引,为什么没有1000?

CREATE TABLE foo(
  id int unsigned primary key auto_increment,
  subid int,  
  json text,
  INDEX(subid,id))

explain select * from foo where subid=1 order by id DESC limit 1000;

+----+-------------+-----------+------------+------+---------------+-------+---------+-------+-------+----------+-------------+
| id | select_type | table     | partitions | type | possible_keys | key   | key_len | ref   | rows  | filtered | Extra       |
+----+-------------+-----------+------------+------+---------------+-------+---------+-------+-------+----------+-------------+
|  1 | SIMPLE      | foo       | NULL       | ref  | subid         | subid | 5       | const | 99748 |   100.00 | Using where |
+----+-------------+-----------+------------+------+---------------+-------+---------+-------+-------+----------+-------------+

0 个答案:

没有答案