How's the performance in php with a request sql with LIMIT in terms of RAM and time of execution -
i'm writing php script i'm facing little question, concrete difference between :
$sql = "select * $table order date desc limit $limit offset $offset"; $result = mysql_query($sql) or die(mysql_error());
and :
$sql = "select * $table order date desc"; $result = mysql_query($sql) or die(mysql_error());
in terms of ram , time of execution used in server ?
edit: opting first sql request, precise need, have recheck amount of data php script build amount of data (smaller) cannot sql pure. (i use fetch_array
in result until have amount want) want know (before wrong), solution faster client (sql + php) , solution more safier in terms of load server ?
edit2 :re-paste order clause
well, isn't answer obvious?
if limit result set of select query, amount of data inside result set reduced. result of this, when looking @ phps memory usage depends on 1 central thing:
if retrieve all of result set in single go, example using
fetchall()
, whole result set read memory.if process result set in sequential order, 1 element of result set read memory @ given time. thus, unless copy that, memory footprint limited.
another thing performance inside php: more elements in result set process, more load generate. limiting size of result set reduce load, unless have way pick range of elements process result set.
as general rule of thumb: always retrieve data require , want process.
Comments
Post a Comment