Search code examples
mysqlperformancelampquery-performance

LAMP/MySQL - run time delay during SQL batch insert


I have a SQL batch insert statement that is properly indexed and verified via explain. I am creating 73 rows with the batch insert. As part of the batch insert I am recording the date/time stamp using NOW() on each inserted record.

During the insert, after 68 records are inserted, there is a 50 second delay before the remaining 5 records are created.

What may be causing the delay during the inserts and what logs should I check?

$values = "";
foreach ($recipients as $recipient) {
    $values = $values . "(" .
              $msg['msg_id'] . "," .
              $recipient['mbr_id'] . "," .
              "NOW()" . "),";
}

// remove the last comma from the value list to terminate the values list
$values = rtrim($values, ",");

$sql = "INSERT INTO message (message_id, member_id, create_dtm)
        VALUES " . $values;

// internal library function using PDO to write to the database 
$pdb->db_commit($sql);  

Any help would be greatly appreciated.


Solution

  • Thanks to the comments regarding the innodb_lock_wait_timeout, I discovered that more memory had to be allocated to MySql.