Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

have you try

Eloquent::unguard();
YourTableModel::insert( $data );
Last updated 2 years ago.
0

Just tried, now it takes 592 seconds....still too much!

Last updated 2 years ago.
0

how long its take by using the cmd line ???

mysql -u root -p1234 your_database_name < code.sql

put this code at the top in the code.sql file

SET @startTime = UNIX_TIMESTAMP();

and this at end of the file

SELECT CONCAT( UNIX_TIMESTAMP() - @startTime, ' seconds' ) AS ' ';
Last updated 2 years ago.
0
peppe@ub-R540:~/Desktop$ mysql --user=root --password=XXX db_test_insert < code.sql

1 seconds
peppe@ub-R540:~/Desktop$

11,177 record

Last updated 2 years ago.
0

how do you are measuring the laravel sql execution time code ??? you need to call DB::getQueryLog(), there is property called time for each query that has been executed

Last updated 2 years ago.
0

I measured the script execution time, using microtime() I run the script and I move on phpmyadmin to see what's happening, the insertions are very slow

The same script using mysqli takes ±25 seconds

Briefly, the script reads the .sql file, explodes every line (which one is an insert query), take che id, check if the id is present in the table, if is present change the insert query in an update query and execute the update, else insert the new row

Only for checking if an id is present in the table, using DB::find(id) - without executing the insert query - the script has an execution time of ±15 seconds

Last updated 2 years ago.
0

Solved, it was a problem of storage engine, changed from InnoDB to MyISAM

Now using:
mysqli->query( $query ): ± 5 seconds
model::create( $data ): ± 35 seconds
db::statement( $query ): ± 25 seconds

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.