0

Magento 2.2

I have to run a huge SQL script which deletes around 2 million entries from url_rewrite by entity_id. This script runs a couple of days, but is interrupted by other processes and so I always get the deadlock SQL error and the script is aborted and I have to restart it manually.

Now I was thinking to write lock url_rewrite while the script runs. How would I do that and is it a good idea?

Thanks!

0

Split the delete querie to batch

like

$batchSize = 1000;
$maxUrlRewriteId = $db->fetchOne('select max(id) from url_rewrite');
for ($i =0; $i<= $maxUrlRewriteId; $i++ ) {
    $db->query('delete from url_rewrite where id between $i*$batchSize and $batchSize * ($i+1) and (your filters here)'
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.