mvnobrega's avatar

How to quickly update millions of records

I have two very large tables, each with over 59 million rows. And I need to generate a slug combining information from both, currently I'm doing it like this:

I've done some other tests, but both are slow, it seems like it will take days to finish, has anyone come across this scenario and could give me some insight?

0 likes
5 replies
jlrdw's avatar

Are fields indexed as needed? With millions it won't be super fast, but with indexing it should help.

There are actually companies that run large updates over night at times due to the number of database records.

Could some older records be archived in a backup database?

Make sure to study and implement good database management techniques.

Only suggestions.

1 like
Tray2's avatar
Tray2
Best Answer
Level 74

@mvnobrega Why are you doing this using php? This sounds like a one time thing to me, so my suggestion is to do it in the database using SQL. You are still going to need to do it in chunks but it will be lots faster.

Other than that I would suggest not ordering the records, since you are updating a value, you should just check for it not being updated.

2 likes
mvnobrega's avatar

@Tray2

Good tip, I'll test it directly with SQL. But I used order because I don't have the ID column, and chunck tries to order by the ID column.

mvnobrega's avatar

@Tray2

I performed the procedure with pure SQL and it really increased the speed of the process. In less than 2 minutes almost 2 million rows were updated, now the whole process should take less than 2 hours :))) Thank you for your help

1 like

Please or to participate in this conversation.