i would say your third method is fast.. thanks for doing this..
Mar 10, 2018
16
Level 3
How to up speed for insert?
Hello! I have simple array for insert to db. It adds 50,000 entries at a time. In total in one table more than 2 million records which need to be entered in a database.
The question is how to speed up the introduction of this data.
I made tests for that.
- When I use next construction, I getting 23400 records per min.
// Inserting one record at a time
foreach ($records as $record)
{
DB::table($table)->insert($record);
}
- When I use next construction, I getting 40 records per min.
// Inserting 50000 records at a time
// I tried to reduce the number of records at a time, but the result is approximately the same
DB::table($table)->insert([$records]);
- When I use next construction, I getting 230000 records per min.
// Inserting 50000 records at a time
// The downside of this construction is that need to generate data for the insert yourself.
DB::insert('INSERT INTO '.$prefix.$table.' ('.$columns.') VALUES '.$values);
What other options can be used in Laravel system for mass data insertion with fast speed? Thanks.
Please or to participate in this conversation.