I
I
Ivan2014-12-23 00:21:44
MySQL
Ivan, 2014-12-23 00:21:44

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;');

2) with grouping (multiselect)
$t=$db->query('SELECT * FROM table1; SELECT * FROM table2;');

i.e.
PHP->MySQL->PHP->MySQL->PHP
or
PHP->MySQL->MySQL->PHP I
will ask with arguments, there may be 30 requests

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Sergey, 2014-12-23
@begemot_sun

and how you were going to receive result in the second case?

B
Boris Benkovsky, 2014-12-23
@benbor

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.

V
Vlad Zhivotnev, 2014-12-23
@inkvizitor68sl

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
Ivan, 2014-12-23
@sait4seo

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 question

Ask a Question

731 491 924 answers to any question