0

I have a database wrapper class for MySQL which allow one query per call currently. I want to extend my database wrapper's support for processing multiple queries at once. It is clear for me that if I use the multi-query feature then I can reduce the server-server communication but I don't know enough what happens inside the MySQL server. Is there a significant overhead in the processing if I send a lot of single queries one by one as multi-queries?

There is a lot of projects depends on the wrapper already and don't want to lower their performance, so if there is any reason why I should not do this, I will realize as a separate feature of the wrapper.

This is my planned solution:

<?php

class MySQLWrapper extends AWrapper{
    public function query($query){
        return $this->multiQuery([$query])[0];
    }
    public function multiQuery(array $queries){
        return $this->doMultiQueryMagic($queries);
    }
}

Or should I change the return $this->multiQuery([$query])[0]; line to return $this->doSingleQueryMagic($query);?

webprogramozo
  • 25
  • 1
  • 1
  • 5
  • I'm no expert but I'd guess if anything you might see a very slight reduction in overhead by sending all the query data at once. But - assuming currently you're not doing anything silly like closing and re-opening your connection every time you run a new query - then I doubt you'd see any meaningful change. You're still sending the same number of queries, it's only the way you initiate that from the client (PHP) side which is different. The real overhead is generally in opening the connection, and of course the nature of what the queries actually do and what they return. – ADyson Dec 18 '18 at 10:56
  • I would say, check it out yourself! [There are answers on how to do PHP benchmarks properly](https://stackoverflow.com/a/8372745/886926) – Erik Terwan Dec 18 '18 at 10:56
  • @ErikTerwan I will do it maybe later, but the technical background of this process can be interesting and good to know, tho. – webprogramozo Dec 18 '18 at 11:31

0 Answers0