Forum Moderators: open

Message Too Old, No Replies

Batch Update for MySQL

How to use a temp table join to do fast updates

         

JimK

9:39 pm on Feb 22, 2009 (gmt 0)

10+ Year Member



Brotherhood of LAN suggested using a insert on a temp table/join to do batch updates. I am developing a multi-vendor addon for Zen-Cart that needs to update tens of thousands of records on a daily basis. Using the standard update statements within ZenCart, an update for a single vendor could take up to an hour for 10,000 records. Using this join statement with the insert statements instead of update reduced it to about 50 seconds: UPDATE `vendors_products_feeds` a,`vendors_products_feeds_temp` b SET a.`products_description`=b.`products_description`, a.`vendors_product_image`=b.`vendors_product_image`,
a.`vendors_product_thumbnail`=b.`vendors_product_thumbnail` WHERE b.`vendors_product_id`=a.`vendors_product_id`. The production code uses the Zen-Cart $sql_data_array to determine which of the fields need to be updated.

[edited by: JimK at 9:48 pm (utc) on Feb. 22, 2009]