4번독수리의 둥지

MySQL DATE_ADD() vs php strtotime() 본문

Database/MySQL

MySQL DATE_ADD() vs php strtotime()

4번독수리 2016. 9. 21. 10:54

$l = 100;

 

// DATE_ADD() : 0 sec

$sql1 = "select * from TABLE where Date > DATE_ADD(NOW() INTERVAL -30 DAY)";
$starttime = time();
for ($i = 0; $i < $l; $i++) {
        mysql_query($sql1);
}
$endtime = time();
echo $endtime - $starttime, "\n";

 

// strtotime() : 7 sec

$date = date('Y-m-d H:i:s', strtotime('-30 days'));
$sql2 = "select * from TABLE where Date > '{$date}'";
$starttime = time();
for ($i = 0; $i < $l; $i++) {
        mysql_query($sql2);
}
$endtime = time();
echo $endtime - $starttime, "\n";

'Database > MySQL' 카테고리의 다른 글

_general_ci Versus _unicode_ci Collations  (0) 2022.12.29
MySQL Covering index  (0) 2017.09.19
SQL JOIN  (0) 2016.02.24
Select tables optimized away  (0) 2015.10.23
Correct indexing when using OR operator  (0) 2015.09.08