String performacne: PHP vs MySQL

Are there any performance issues when using a MySQL function CONCAT()

in a select query? Is it faster / slower / negligible for simple selection and formatting strings for presentation using PHP after the result is returned from the database? Or is it a more complex SQL query with multiple calls to CONCAT()

that returns a string already formatted for better representation?

those. this is:

select CONCAT(lastname, ', ', firstname) from people;


Faster / slower / No difference:

    $query = 'Select lastname, firstname from people';

    $name = $data['lastname'] . ', ' . $data['firstname']; //OR
    $name = sprintf("%s, %s", $data['lastname'], $data['firstname']);



source to share

2 answers

You are better off in almost all cases, doing filtering and massaging the data with the SQL engine versus the web server.



If you plan on doing hundreds of thousands of such operations concurrently, it doesn't matter where you are doing the string concatenation from a performance standpoint. The potential time savings will be so small that they probably won't even be measured.



All Articles