简体   繁体   中英

Mysql [5.6] Innodb select query order by id asc limit 100 is much slower than desc

My table schema looks like this:

create table myTable (
   id int(11) not null auto_increment,
   name varchar(255) not null,
   PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=894609724 DEFAULT CHARSET=utf8;

Total number of the rows are not more than 500. Rows with id < 894609000 are deleted. And does not exist in table

When I do: SELECT * FROM myTable ORDER BY id DESC LIMIT 100; it response time is 50 ms.

But when I do: SELECT * FROM myTable ORDER BY id ASC LIMIT 100; its response time is 10 sec. which is 200 times slower than the reverse order query.

Could anyone please tell me why this kind of behaviour?

EDIT: I did EXPLAIN {query} too, it gives the same result for both the queries. 解释 {query} 这个结果

Please do these 3 statements and provide the results:

SHOW TABLE STATUS LIKE 'myTable';
OPTIMIZE TABLE myTable;
SHOW TABLE STATUS LIKE 'myTable';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM