mysql using

select * from account where account.gender="male" order by createTime limit 100,10

没有添加索引时执行的时间为0.076s,mysql会花费大量时间扫描需要需要丢弃的数据。

优化这类查询可以使用延迟关联,添加索引(gender,createTime)

create index g_c_ind on account (gender,createTime) using BTREE

在使用如下的sql语句进行查询数据,在查询过程中,会使用覆盖索引,先选取符合条件的id,然后再使用id利用索引查找符合条件的数据

 
select * from account inner join(select accountId from account where gender="male" order by createTime limit 100,10) as x using (accountId)

posted @ 2015-09-01 13:47  程序猿进化之路  阅读(139)  评论(0)    收藏  举报