简体   繁体   中英

MySQL Update a Complete Column data from Another Table with same Primary Key (30 Million Row)

I have two tables: Final and Primary in my MySQL database. Final Table:

UID (Primary Key), Surface (Varchar), BCD_Value (Int , Index), Env_Value (Int)

Primary Table:

UID (Primary Key), BCD_Value (Int , Index)

There are 30 Million rows in each table. Primary Table has the correct BCD_Value. I have to update Final Table's BCD_Value with values from Primary on matching UID.

I was using following in MySQL command line

update Primary pri, Final fin set fn.BCD_Value = pri.BCD_Value where fin.UID = pri.UID

But it does nothing after 36 hours.

Further, I have implemented a code in perl which creates update statement for 5000 rows at time (loops it for 30 million/ 5000 times). Now it is working but I desperately need to fasten it.

try converting into ANSI SQL-92 syntax

UPDATE Final fin INNER JOIN `Primary` pri
       ON fin.UID = pri.UID
SET fn.BCD_Value = pri.BCD_Value

it takes time to update all records because it updates the indexes as well.

try removing the index on Final.BCD_Value first then add again after the update has been made.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM