Last active
December 10, 2015 05:48
-
-
Save toshimaru/4390402 to your computer and use it in GitHub Desktop.
compare select query (mysql).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
these queries are same run time. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$con = mysql_connect('localhost', 'root', 'passwd'); | |
if (!mysql_select_db('sample_db')) { | |
die('Could not select database: ' . mysql_error()); | |
} | |
$sql = <<<EOF | |
select * from ptable as p | |
inner join adtable as ad on p.pid = ad.pid | |
inner join atable as a on a.aid = ad.aid | |
where a.aid = | |
EOF; | |
// $sql = <<<EOF | |
// select * from adtable as ad | |
// inner join atable as a on a.aid = ad.aid | |
// inner join ptable as p on p.pid = ad.pid | |
// where a.aid = | |
// EOF; | |
// $sql = <<<EOF | |
// select * from atable as a, adtable as ad , ptable as p | |
// where a.aid = ad.aid | |
// and p.pid = ad.pid | |
// and a.aid = | |
// EOF; | |
// $sql = <<<EOF | |
// select * from adtable as ad, atable as a | |
// where a.aid = ad.aid | |
// and a.aid = | |
// EOF; | |
$time_start = microtime(true); | |
foreach (range(1,10000) as $id) { | |
$_sql = $sql . $id; | |
$result = mysql_query($_sql, $con); | |
while ($row = mysql_fetch_array($result)) {} | |
} | |
$time = microtime(true) - $time_start; | |
echo "{$time} min."; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment