在大数据情况下MySQL的一种简单分页优化方法_MySQL
通常应用需要对表中的数据进行翻页,如果数据量很大,往往会带来性能上的问题:root@sns 07:16:25>select count(*) from reply_0004 where thread_id = 5616385 and deleted = 0;+———-+| count(*) |+———-+| 1236795 |+———-+1 row in set (0.44 sec)root@sns 07:16:30>select idfrom reply_0004 where thread_id = 5616385 and deleted = 0order by id asc limit 1236785, 10 ;+———–+| id |+———–+| 162436798 || 162438180 || 162440102 || 162442044 || 162479222 || 162479598 || 162514705 || 162832588 || 162863394 || 162899685 |+———–+10 rows in set (1.32 sec) 索引:threa_id+deleted+id(gmt_Create) root@snsgroup 07:16:49>select * from (select id-> from group_thread_reply_0004 where thread_id = 5616385 and deleted = 0-> order by id desc limit 0, 10)t order by t.id asc;+———–+| id |+———–+| 162436798 || 162438180 || 162440102 || 162442044 || 162479222 || 162479598 || 162514705 || 162832588 || 162863394 || 162899685 |+———–+10 rows in set (0.87 sec) 可以看到性能提升了50%以上。 |