Several small queries compared to one long query. Which one is more effective?

Which approach is more effective:

  • One long request:

    "SELECT COUNT( * ) AS num
    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
    
  • Break the longer query into several single table queries:

    uid = "SELECT UID FROM identity WHERE 'abc' IN (google, facebook, twitter, linkedin)";
    cnumber_from_usertable = "SELECT cnumber FROM users WHERE UID = 'uid'";
    cnumber_from_jobtable = "SELECT cnumber FROM jobs WHERE JID = 24";
    
    if(cnumber_from_usertable == cnumber_from_jobtable)
        //Some code here
    else
        //Some code here
    
+5
source share
2 answers

measure the difference in the microgel ;-) I would go with the only question, though, fewer connections, less waiting time, and it is designed to handle such things.

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.';
?>
+6
source

, . MYSQL , . INNODB , tmp, , , , . MYSQL , , .

, , Infinidb INfobright, , MYSQL .

, , , , , MYSQL , . BUt, MYSQL , .

.

+3

All Articles