Slow MySQL selects with where PK > x -


i have table 5 million rows of following structure:

create table `books` (   `asin` char(10) character set latin1 not null,   `title` varchar(512) not null, ...other fields...   primary key (`asin`),   key `lang` (`lang`) ) engine=myisam default charset=utf8; 

i'm trying run script on all, use "select * books asin > x limit 10000" , remember last pk.

i expected query fast since i'm querying pk, performance degrading query taking 1 minute (used better in beginning). why happen?

explain example:

mysql> explain select * books asin > 'b000ot86oy' limit 10000; +----+-------------+-------+-------+---------------+---------+---------+------+---------+-------------+ | id | select_type | table | type  | possible_keys | key     | key_len | ref  | rows    |       | +----+-------------+-------+-------+---------------+---------+---------+------+---------+-------------+ |  1 | simple      | books | range | primary       | primary | 10      | null | 4670633 | using | +----+-------------+-------+-------+---------------+---------+---------+------+---------+-------------+ 

i able mitigate issue performing alter table books order asin asc. imagine issue rows physically far apart on disc, after doing above, query became instantaneous.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -