Mysql update query tooks too long with magento cat

2019-08-27 22:02发布

问题:

I am having problem in update query with magento "catalog_product_entity_decimal" table. I need to update product prices dynamically every one hour and the store has ~50k products right now. So i didnt followed the magento way of product price save to bulk update, instead I followed direct product price update in "catalog_product_entity_decimal" table which is giving results.

My query is like this $query = "UPDATE catalog_product_entity_decimal val SET val.value = '$final_rounded_price' WHERE val.attribute_id = 75 AND val.entity_id = $product_id";

It took 1307.1874998760223 seconds to update to 47701 products. Which is nearly 20 minutes - which is too slow when we do in the live site update.

It did reflects in the store correctly but takes too long to update which is big problem. also without this query update the time taken for this process is mili seconds only. So this table is the problem for taking time then i tried updating some dummy table update which has the nearly same records for my own purpose which took 8.5674998760223 seconds to update to 47701 products.

That query is something like this

$query = "UPDATE product_attributes val SET val.price = '$final_rounded_price' WHERE val.attr_id = $attr_id AND val.product_id = $product_id";

I tried with different server which is more or less same result. So i see "catalog_product_entity_decimal" this table has so many references which must be the reason for taking long time.

I am not an expert in mysql side and i couldnt able to reduce the mysql update time with this table. Please kindly advice how can i run update query on table "catalog_product_entity_decimal" faster to update prices in bulk.

Attached the screenshot of the table "catalog_product_entity_decimal" for reference.

Development Server configuration : Cent os 6 with php 5.3, 8 GB RAM, Magento environment - 1.7.02 - Running default store without any change in code/db.