我在我的应用程序中发现了mysql的execute()函数的缓慢性。我设计了一个简单的sql查询来说明这个问题:SELECT * FROM `cid444_agg_big` c WHERE 1
一。在
^{pr2}$
在mysql shell中运行这个查询,可以得到0.27秒,或者快10倍!!!在
我唯一的想法是返回的数据的大小。这将返回21600个“宽”行。所以有很多数据被发送到python。数据库是本地主机,因此没有网络延迟。在
为什么要花这么长时间?在
更新更多信息
我用php编写了一个类似的脚本:$c = mysql_connect ( 'localhost', '*****', '****', true );
mysql_select_db ( 'cachedata', $c );
$time_start = microtime_float();
$sql="SELECT * FROM `cid444_agg_big` c WHERE 1";
$q=mysql_query($sql);$c=0;
while($r=mysql_fetch_array($q))
$c++;//do something?
echo "Did ".$c." loops in ".(microtime_float() - $time_start)." seconds\n";
function microtime_float(){//function taken from php.net
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
打印:Did 21600 loops in 0.56120800971985 seconds
这将循环所有数据,而不是一次检索所有数据。PHP似乎比python版本快了6倍。。。。在