N
N
Nikita Gusakov2012-11-09 20:30:14
PHP
Nikita Gusakov, 2012-11-09 20:30:14

Which is better: a request queue or one, but a large one?

The request/s are formed in a loop, parsing the associative array, which is better - to form one request, or to execute your own for each new line?

Answer the question

In order to leave comments, you need to log in

6 answer(s)
H
Hint, 2012-11-09
@hell0w0rd

What requests are we talking about? Splitting with a semicolon?
I can say for sure that a multiline INSERT (one INSERT with several rows) is much faster than several separate INSERTs.

R
rakot, 2012-11-09
@rakot

In most cases, this issue is saving on matches.
In this case, a large query will be simple and easy to execute, which means it will be fast.
Many small requests will most likely not reach the database at all, and the result will be taken from the cache, which means it will also be executed quickly.
Do what works best for you, and save the desire to optimize for places where it's really needed.

V
vsespb, 2012-11-09
@vsespb

Either it doesn’t matter at all, or something in between is optimal - one request for every 100-1000 iterations.

E
edogs, 2012-11-09
@edogs

One request.
This is the most common (and thankfully the easiest to fix) thing to do when doing something like foreach() mysql_query; that with just something even with 100 array elements results in 100 queries. Horror fear and trembling.

V
vsespb, 2012-11-10
@vsespb

in a transaction is faster - that's why it is a transaction.
instead of 100 update, by the way, sometimes you can pervert and get by with one multiline insert… on duplicate key update

R
run182, 2020-12-28
@run182

Looking how difficult 1 request. Sometimes >100 small requests are better than 1 really complex one.
But often there is a 3rd option - 2 or 3 small requests with subsequent processing of the received arrays.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question