Answer the question
In order to leave comments, you need to log in
Speed of Mysql fetches, should I group queries or select one at a time?
I'm doing a project on a bunch of php, mysql. I want to know whether it is worth grouping sql queries in order to execute them at once i.e. (simplified example)
1) without grouping
$t[1]=$db->query('SELECT * FROM table1;');
//...какой-то код на пхп
$t[2]=$db->query('SELECT * FROM table2;');
$t=$db->query('SELECT * FROM table1; SELECT * FROM table2;');
Answer the question
In order to leave comments, you need to log in
1. Whatever the answer to your specific question, for single requests, this is "saving on matches". In any case, this applies to database queries with more than 1000 rows (the numbers, of course, are taken just like that, but you get the point).
2. Take specific requests from your application (do you need an answer for this, right?) and do a test. On real requests in your system, you will receive the answer you need.
3. Don't use * in a selector. This already increases the request time.
Do you keep a connection to the database persistent?
If you keep - then until you plunge into highload (more than 1k rps on your page), then it doesn't matter at all.
If you do not hold, then there will be additional overhead costs for establishing a connection. But there are also few of them with a small load.
So in this case, you need to proceed from how it will be more readable and more convenient for you yourself.
I don't use persistent connection, should I use it? (I didn’t use it because I somehow googled a bunch of problems with it, they say processes are multiplying, etc.), if there is a sensible link on pdo persistent connect and how to cook it properly, I will be grateful.
As for readability, it’s possible not to immediately execute the request, but first collect them and concatenate them, and then, for example, make
such an option, after all, has the right to life?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question