Answer the question
In order to leave comments, you need to log in
How to speed up MySQL UPDATE by 100k rows?
Good afternoon!
There is a table with the goods on 100 records.
You need to select all the records from it, make an extra charge (PHP f-i does this), and then do an UPDATE of this record.
Such a request
$this->products = (new Query())
->select(['p.id', 'p.price'])
->from(['products p'])
->all();
$this->products = (new Query())
->select(['p.id', 'p.price'])
->from(['products p']);
foreach($this->products->batch(1000) as $product) {
//....
}
Answer the question
In order to leave comments, you need to log in
Do update not by one record, but by batches using transactions. like 1000 jokes.
It will be noticeably faster.
Get rid of ActiveRecord rewrite the query in low-level mysqli or PDO and it will run for you in a few seconds.
PS Or at least Yii DAO or Yii Query Builder
Is it not an option to mark up directly in the database?update product set price = price * 1.3
Do not receive data from the database, but calculate your margin using the database itself.
If you show the code of the function that calculates the markup, then I will help you make a request for UPDATE
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question