Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating large MySQL table

I have a table of 10000 product in my MySQL database. I would like to update all the records in a fastest way. I am using Laravel with MySQL.

For better solution I can change technologies also. Right now it takes almost half hour to update the whole table.

I would like to update that table in a fastest way. What should I do?

UPDATE

I am using Laravel model like below

DB::table('products')->where('product_id',$product_id)->limit(1)->update(array('prodcut_quantity' => $prodcut_quantity));
like image 897
julious ceazer Avatar asked Sep 29 '22 05:09

julious ceazer


1 Answers

Performance is more often affected by the table design than the statement being run against it. Make sure that your table is properly indexed and is using an efficient storage engine and make sure that your data is normalised. As mentioned in the comments, make sure you are using a single update query rather than multiple ones (or at the very least as few statements as you can possible use). If you are looking for code optimisation then you will need to post some up for us to work with. If you could post up details of your table design, indexes and storage engine it would also be a help.

like image 51
MuppetGrinder Avatar answered Oct 02 '22 14:10

MuppetGrinder