很简单的100w条数据用 select id from guestbook order by id desc limit 190000,30 查询起来,页面不动弹了。
后来请教了高人,换了下面的语句
SELECT * FROM guestbook INNER JOIN (select id from guestbook order by id desc limit 190000,30 )as d ON guestbook .id=d.id order by guestbook .id desc limit 30
结果2s结果就出来了,太神奇了。
研究了一下这个语句还可以简写为
SELECT * FROM guestbook INNER JOIN (select id from guestbook order by id desc limit 190000,30 )as d ON guestbook .id=d.id
关键问题就在两个sql语句之间的差别
select * from guestbook order by id desc limit 190000,30 //这个会很慢
select id from guestbook order by id desc limit 190000,30 //这个可能是加了索引,比较快,而且只查了id字段,然后把查询的结果再做个内连接就得到需要的数据了