Efficient pagination with MySQL -


i'm trying speed pagination of data on site. i'd use following query, when explain says needs scan on 40,000 rows:

select `item`.`id`, `user`.`id`  `items` `item`  left join `users` `user`      on (`item`.`submitter_id` = `user`.`id`)  `item`.`made_popular` < "2010-02-08 22:05:05"    , `item`.`removed` != 1  order `item`.`made_popular` desc  limit 26 

but if add lower bound "made_popular" field needs scan 99 rows (the number of items between 2 dates).

select `item`.`id`, `user`.`id` `items` `item`  left join `users` `user`      on (`item`.`submitter_id` = `user`.`id`)  `item`.`made_popular` < "2010-02-08 22:05:05"      , `item`.`made_popular` > "2010-02-07 22:05:05"      , `item`.`removed` != 1  order `item`.`made_popular` desc  limit 26 

both queries use index have on "made_popular" column. in both cases shouldn't need scan 26 rows, assuming there no "removed" items? guess solution go second query , add lower bound low enough give me 26 items, seems odd should have workaround that.

but when explain says needs scan on 40,000 rows: 

it misunderstand rows means. means approximate amount of rows used return result regardless limit clause.

so shouldn't worry in case - mysql stops fetching data right after reaches limit amount.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -