Is there a way without using a script to run an UPDATE that won’t slow the DB by only doing a certain amount of rows at a time?
I’m performing
UPDATE .. SET .. FROM .. INNER JOIN .. ON ... WHERE
and it’s going to update 3,171 rows in a very large table.
I don’t want to lock the DB or slow it down. Any ideas?
NOTE:
As per the MySQL docs for UPDATE: For the multiple-table syntax, UPDATE updates rows in each table named in table_references that satisfy the conditions. In this case, ORDER BY and LIMIT cannot be used.
I was performing an INNER JOIN and LIMIT was not allowed to be used, using LIMIT as a solution does not work in this case.
Believe it or not, you can use
LIMIT!I know it sounds weird, and it is non-deterministic, but it’s so handy!
Edit
However, for updating joins, limit is not supported. However, there is an solution!
Use variable to control how many rows are updated. Here’s a general look at how it works:
Here I’m updating the first/next 100 rows that match the join criteria – you can set it to whatever number you like.