doudeng1870 2013-02-25 19:39
浏览 53
已采纳

Mysql php / pdo语句执行时间在刷新时大不相同

I have code similar to the following in a php document that communicates with a mysql database:

$db = new PDO('mysql:host=127.0.0.1;dbname=db;charset=UTF-8', 'name', 'pw',array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_PERSISTENT => true, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY=>true));    

$stmt=$db->prepare("SELECT SUM(anything)
                                FROM table
                                WHERE date IN (SELECT date FROM table WHERE something=:something AND somethingElse=:somethingElse) 
                                AND somethingElse=:somethingElse1");

This code takes a long time to run in a browser the first time through... if executed again via a refresh it runs over 100 times faster. I'm trying to figure out what causes a pdo statement like this to run so much faster on a refresh and can't figure it out.

  • 写回答

5条回答 默认 最新

  • dongtazu3080 2013-02-25 19:41
    关注

    That's mysql's query cache kicking in... as long as your RAM (read: MySQL cache memory allocation) is sufficiently large, this will happen to almost any SELECT.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler