主键在数据查询中带来的速度提升

 下面结合具体查询结果进行比较: 数据库大概40多万,主键是id

  情况一: order by time   用时间:0.467s

   select time from filecopyinfo where uniqueid=3322060240 ORDER BY time desc limit 0,10;  

 

 情况二:order by time  +格式化时间 ‘%Y-%m-%d %T’   用时间:超过一秒 1.074s
 select  date_format(time,'%Y-%m-%d %T') time from filecopyinfo a where uniqueId=3322060240  ORDER BY id DESC limit 0,10

 

情况三:order by time   select*    用时间超过:0.456s

   select * from filecopyinfo where uniqueid=3322060240 ORDER BY time desc limit 0,10;  

 

以下考虑用Id主键进行排序

     情况一: order by id 用时间:0.001s    提速倍数:400多倍

      select time from filecopyinfo where uniqueid=3322060240 ORDER BY id desc limit 0,10;  

      情况二:order by time  +格式化时间 ‘%Y-%m-%d %T’   用时间仅仅秒 0.001s

      select  date_format(time,'%Y-%m-%d %T') time from filecopyinfo a where uniqueId=3322060240  ORDER BY id      DESC    limit 0,10

 

情况三:order by time   select*    用时间仅仅0.001s 左右 

   select * from filecopyinfo where uniqueid=3322060240 ORDER BY time desc limit 0,10;  

 

以上实验可以看出主键排序在查询中的重要作用。

posted @ 2014-07-16 14:27  跛脚前行,从心开始  阅读(779)  评论(0)    收藏  举报