Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

Várias consultas pequenas versus uma única consulta longa. Qual deles é mais eficiente?


medir a diferença de microtempo;-) Eu iria com a consulta única, porém, menos conexões, menos tempo de espera e é projetado para lidar com esse tipo de coisa.

http://www.phpjabbers.com/measuring-php -page-load-time-php17.html
<?php
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$start = $time;
?>
"SELECT COUNT( * ) AS
FROM (

    SELECT users.UID, cnumber
    FROM users
    JOIN identity ON users.UID = identity.UID
    WHERE  'abc'
    IN (google, facebook, twitter, linkedin)

) AS userfound
JOIN jobs ON userfound.cnumber = jobs.cnumber
WHERE JID = 24";


if(resultfromquery == 1)
    //Some code here
else
    //Some code here

<?php
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$finish = $time;
$total_time = round(($finish - $start), 4);
echo 'Page generated in '.$total_time.' seconds.';
?>