`

mysql中的一个limit的调优

阅读更多
一般来说,数百万的记录,取一定范围的条数,用LIMIT
select * from mytable where col = xxx limit offset, limit;
但用explain一下,会发现是all全表扫,解决的一个好的办法是建立索引于col列后,
假如ID是递增的话,可以这样
select * from mytable where id > offset and id < offset + limit and col = xxx



分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics