排序、分页优化

排序优化主要是利用索引的有序性,

select * from table_a where id > 10 order by create desc limit 10可以建立一个联合索引id,create

当按照id查出数据后已经是按照create有序了。

对于分页查询 select * fromtable_a order by id desc limit m n,如果m很大会扫描很多行,可以利用where语句来限制扫描的行数

select * fromtable_a wehre id > x order by id desc limit m n,x的值根据第几页和取的数据来设置

select * fromtable_a wehre id > 25000 order by id desc limit 20,跟select * fromtable_a order by id desc limit 25000,20的结果一样,但是扫描的行数相差很大。

猜你喜欢

转载自lishichang.iteye.com/blog/2187982