wp-cli / search-replace-command

Searches/replaces strings in the database.
MIT License
57 stars 45 forks source link

Chunk query that can potentially OOM #153

Closed aidvu closed 3 years ago

aidvu commented 3 years ago

Unbound query has potential to return millions of rows, and it's fairly easy to run into memory problems.

e.g. we had a problem with a ~4GB DB that was returning 13 million rows to check for the meta_value column.

The fix loops through the table fetching 1000 at a time. Added ORDER BY statement, so we can safely iterate through the primary keys.

Using ASC ordering, so the new items come last, in case something gets added while it's running.

aidvu commented 3 years ago

Review with hide whitespace changes. :)

schlessera commented 3 years ago

Thanks for the PR, @aidvu !

aidvu commented 3 years ago

Glad I could help.