W
W
Wade2k2018-03-09 12:58:16
MySQL
Wade2k, 2018-03-09 12:58:16

How to speed up Update in a loop on a large table?

There is a table table1 with 3 million rows. There is an index on id.
It is necessary to update one field by id in a cycle in php for all rows in sequence.
I wrote a script in php, everything is fine, but every 1000 update is processed in 8 seconds. So I will wait until tomorrow)
Explain looked, the index is used. What could be the problem?
innodb table

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Stanislav Menshov, 2018-03-09
@SWEBB

Maybe I misunderstood, but why run a cycle here if the entire table is updated, where all IDs are sorted sequentially.
It's just possible

UPDATE table1
SET field = 'value'

B
Boris Korobkov, 2018-03-09
@BorisKorobkov

1. create temporary table t_tmp ...
2. insert into t_tmp values (...), (...), ...
3. update ...
4.drop temporary table t_tmp

D
Denis, 2018-03-09
@sidni

I ran into this on a project with huge prices and there the simplest solution is to delete and re-insert in portions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question