MYSQL Insert And Delete At The Same Time IMPACT

- 1 answer

Here is the scenario.

  1. I have a schedule job running every minute which inserts data into a MYSQL table "demo". The total number of records per day are 60*24 = 1440.

  2. Table demo already has 55000 records.

  3. I want to clean records less than today's date. Therefore I am using below code to do the work daily at 10.00 AM.

$demo = Demo::whereDate('created_at','<', Carbon::today());

if(count($demo) > 0)

Now a point will come where at the same time I am inserting to the same table and deleting from the same table.

I want to know that it will be safe? Or there will be an error or any other impact.



I don't think this will be an issue, since Carbon::today() returns 00:00:00 as time and you are executing the deletion job at 10:00:00. Only records that are inserted more than 10 hours ago will be deleted.