最近在维护一个项目,项目使用的是mySQL数据库,为了加快查询速度,我使用了存储过程,因为我本机上只有百万级的数据,我写的储过程,在本机运行完全正常,我对比了下,使用存储过程用时1秒左右,不用存储过程,直接用select.....用时4秒左右。如下图:
可换到服务器上,不知怎么的,这个存储过程就不给力了,存储过程跑一次需要1分20秒左右,而直接使用sql的select....则只需要几秒!
这是神马情况?由于是新手,存储过程也不是很会,求大神赐教Mysql存储过程

解决方案 »

  1.   

    存储过程并不能加快查询
    把select拿出来  对比两台机器的explain
      

  2.   

    以文本方式贴出你的语句和存储过程。 图形并不方便它人阅读。贴出 explain select ... 和 show index from .. 以供分析。
      

  3.   

    sql语句:
    select VAR_VALUE,TIMESTAMP from tbl_value where var_id =400325 and plc_id=1 and deviceid=13596037955 and TIMESTAMP>=1372608000 and TIMESTAMP<=1375286400 order by id asc;存储过程:
    reate PROCEDURE proc_common_energy_report(in varid int, in deviceid long, in plcid int, in starttime long, in endtime long)
    begin
    select VAR_VALUE,TIMESTAMP from tbl_value where var_id=varid and deviceid=deviceid and plc_id=plcid and TIMESTAMP>=starttime and TIMESTAMP<endtime order by id asc;
    end;调用存储过程:
    set @varid=400325;
    set @deviceid=13596037955;
    set @plcid=1;
    set @starttime=1372608000;
    set @endtime=1375286400;call proc_common_energy_report(@varid,@deviceid,@plcid,@starttime,@endtime);sql语句的EXPLAIN:存储过程的EXPLAIN:
    可EXPLAIN 我都看不懂........