jeudi 31 décembre 2015

Rails 3 - delete_all doesn't support limit scope whereas MySQL supports it

I have a table with 9 millions of records. I was periodically syncing this data to a third party. I am keeping a column that tells if a particular row has already been deleted or not.

Now I need to delete almost 6 million synced rows and I am not sure if running

Model.where(:sync_flag => true).delete_all

would be a nice idea. There are hundreds of inserts per second and I think it might result in locking the table in a way that would hurt/block the inserts ( MySQL expert needed here to correct )

With the above prologue, I thought of using a delete with a limit clause in a loop to delete all the records until none left but with the following

Model.where(:sync_flag => true).limit(5000).delete_all

it raised an exception delete_all doesn't support limit scope.

Is there a workaround to deal with the issue without leaving the Rails environment ?

Aucun commentaire:

Enregistrer un commentaire